Let's take a moment back from placement new to see the relationship between the new operator and operator new. To create an object on the stack, you should use the new operator. It allocates both memory and calls constructors for objects. If you only want to allocate memory, you should call the operator new function; it will not call the constructor. If you want to customize your memory allocation process when the heap object is created, you should write your own operator new function and then use the new operator, the new operator will call your customized operator new. if you want to create an object in a memory with obtained pointers, you should use placement
New.
In C ++
A * A = new ();
Perform the following operations in two parts:
Part 1:
Call the oprator new (size_t size) function to allocate memory.
Call constructor ()
Oprator new (size_t size)
The compiler will check whether a has rewritten the function. If not, it will call the global operator new () function.
Therefore, if you want to change the memory allocated by the system to the object on the stack, you must control the memory allocated by yourself.Algorithm. Rewrite the operator new () function.