lovecreatesbea...@gmail.com wrote:
If the built-in operator keyword new doesn't allocate memory on heap
and it calls global operator new (::operator new) or class member
operator new to do that. What are the two kinds of operator new used to
allocate heap memory?
This is the confusing part of C++. When you have something like:
T* ptr = new T;
the followings are performed:
1. Either the default operator new or an overloaded version is called
to obtain raw memory large enough to fit a T object.
2. The constructor of T is called.
The operator new, as in the function you can overload, only allocates
raw memory. The keyword new does that plus constructing the object.
By default, new allocates memory from the heap, or the free store. You
can overloaded either globally or specific to a class to provide
alternate memory management, usually to
- tweak performance
- inspect memory allocation
- debug the program
>
Before there aren't global and member operator new, the built-in
operator keyword new does really allocate heap memory, right?
That, I don't know.
Ben