1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
In sections ref(NEWARRAY), ref(DELETEARRAY) and ref(DELETEPTRS)
tt(operator new[]) and tt(operator delete[]) were introduced. Like
tt(operator new) and tt(operator delete) the
operators tt(new[]) and tt(delete[]) may be overloaded.
As it is possible to overload tt(new[]) and tt(delete[]) as well as
tt(operator new) and tt(operator delete), one should be careful in selecting
the appropriate set of operators. The following i(rule of thumb) should always
be applied:
quote(If tt(new) is used to i(allocate memory), tt(delete) should be used
to i(deallocate memory). If tt(new[]) is used to allocate memory,
tt(delete[]) should be used to deallocate memory.)
By default these operators act as follows:
itemization(
itt(operator new) is used to allocate a single object or
primitive value. With an object, the object's constructor is
called.
itt(operator delete) is used to return the memory allocated by tt(operator
new). Again, with class-type objects, the class's destructor is
called.
itt(operator new[]) is used to allocate a series of primitive values or
objects. If a series of objects is allocated, the class's default constructor
is called to initialize each object individually.
itt(operator delete[]) is used to delete the memory previously allocated
by tt(new[]). em(If) objects were previously allocated, then the destructor
is called for each individual object. Be careful, though, when pointers to
objects were allocated.
hi(pointer: to object) If em(pointers to objects) were allocated the
destructors of the objects to which the allocated pointers point won't
automatically be called. A pointer is a primitive type and so no further
action is taken when it is returned to the common pool.
)
|