array new-expressions: proposal

John Wilkinson jfw at cthulhu.engr.sgi.com
Fri Jan 21 22:08:06 UTC 2000


Daveed Vandevoorde wrote:
> 
> Matt Austern wrote:
> [...]
> > PROPOSAL A.
> >
> > No version of operator new[] is a special case.
> [...]
> > PROPOSAL B.
> >
> > ::operator new[](size_t, void*) is a special case.  For that
> > version of operator new[] only, n1 = n * sizeof(T).  We do not
> > store the number of elements in such an array anywhere.
> 
> There is a reason that placement new is called _placement_ new:
> the intent was to allow the placement of objects and arrays at a
> given address.  In effect, it's a way to specify a "this" pointer
> to a constructor.
> 
> So I think Proposal A is really not a good idea.
> 
>         Daveed

Certainly that was the intent; it's just that it doesn't work very well
in the vector case.  There's no good way to run the destructors except
by overriding operator delete; but then delete[] won't release storage
for a normal vector new.  I think it would have been better if hiding
the allocation overhead had been the responsibility of operator new[]
and not of the new expression; it would have been better to allow
delete[] to call a placement delete function (which could be stashed
along with the count); but that's not the way it is.  I don't have
really strong feelings about the choice between A and B, however.  I'm
leaning towards A today out of frustration.

-- 
John Wilkinson




More information about the cxx-abi-dev mailing list