C++ Migration Guide

Array Forms of new and delete

The C++ standard adds new forms of operator new and operator delete that are called when allocating or deallocating an array. Previously, there was only one form of these operator functions. In addition, when you allocate an array, only the global form of operator new and operator delete would be used, never a class-specific form. The C++ 4.2 compiler did not support the new forms, since their use requires an ABI change.

In addition to these functions:

void* operator new(size_t);

void operator delete(void*);

there are now:

void* operator new[](size_t);

void operator delete[](void*);

In all cases (previous and current), you can write replacements for the versions found in the run-time library. The two forms are provided so that you can use a different memory pool for arrays than for single objects, and so that a class can provide its own version of operator new for arrays.

Under both sets of rules, when you write new T, where T is some type, function operator new(size_t) gets called. However, when you write new T[n] under the new rules, function operator new[](size_t) is called.

Similarly, under both sets of rules, when you write delete p, operator delete(void*) is called. Under the new rules, when you write delete [] p, operator delete[](void*) is called.

You can write class-specific versions of the array forms of these functions, as well.