C++ allows overloading operator new
- both global and per-class - usual operator new
, operator new[]
used with new[]
stat
My primary usage is to create a large array of objects. Its performing much better and has less overhead to allocate the memory in a whole block, i.e. using VirtualAlloc from Win32 (when programming windows). Then you just pass a ptr within that block to each objects placement new such as:
char *cp = new char[totalSize];
for(i = 0; i < count; i++, cp += ObjSize)
{
myClass *obj = new(cp) myClass;
}