Jim Helman (jimh++at++surreal)
Wed, 21 Feb 96 15:13:39 -0800
Bjarne. You'll need to get him to change the language......
"The global operator new() and operator delete() are used for
arrays of class objects (5.5.3, 5.3.4)"
- Annotated C++ Reference Manual (12.5, p. 283)
Note that even where you can do this (for the global new
operator), you probably don't want to.
Overloading the global new operator for array allocation is
baaaaaaad, since you cannot safely use delete[] on such an
array. When using a new with additional arguments, the
allocation cannot include the hidden array element count used
by delete[]. The reason the count is not maintained is that
the extra argument to the overloaded new could be for
placement, e.g. malloc(n*sizeof(class)), which bypasses the
usual sizeT argument. No extra storage, no place to put the
count. BUT delete[] doesn't know the array doesn't have a
valid element count, and so it can do very bad things like
invoking the destructor many times beyond the limits of the
array.
Just another tragic case of broken language design.
rgds,
-jim helman
jimh++at++surreal.asd.sgi.com
IRIS Performer/Cosmo3D Java Library
415/933-1151
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:26 PDT