Home > Back-end >  On the back of the new this kind of grammar meaning
On the back of the new this kind of grammar meaning

Time:09-16

This source code from the JVM constantPool. CPP

 
ConstantPool * ConstantPool: : the allocate (ClassLoaderData * loader_data, int length, TRAPS) {
ArrayInt size=ConstantPool: : size (length);
Return new (loader_data, size, MetaspaceObj: : ConstantPoolType, THREAD) ConstantPool (tags);
}


My confusion is a new and a pile of what is in the ConstantPool, I thought it was casts

CodePudding user response:

The new operator should be overloaded

CodePudding user response:

This is not a casts, placement is new
 # include & lt; Algorithm> 
Using namespace STD.
Class A {
Int _c.
Public:
A (int) c: _c (c) {}
Void * operator new (size_t n, void * PTR,... ) {
Cout & lt; <"Place new is call" & lt; Return PTR.
}
};

Int main ()
{
Void * p=malloc (sizeof (A));
A * pa=new (p 10) A, (10).

Return 0;
}

Means in constructing an A p address

CodePudding user response:

This is called placement new usage, on the specified a block of memory to use new heap memory allocated memory specific size
  • Related