[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]
Re: c++ 2.1 diffs
- To: <roger>, <vlad!mark>, <xtech>
- Subject: Re: c++ 2.1 diffs
- From: Michael McClary <michael>
- Date: Thu, 28 Jun 90 01:50:53 PDT
> 4. The correct syntax for deleting an array is "delete [] p;". The former
> syntax, in which an expression within the brackets was required to give the
> number of elements in the array being deleted, is now officially an
> anachronism. [Implemented.]
>
> Mr. Hill & Roger: forget what I said before. Since "operator new(..)"
> and "operator delete (..)" can be provided by the user, I don't see
> how it is *possible* for the language to implement this. (For those
> who missed the verbal conversation) The issue is: if you are deleting
> an array of objects with destructors, how does C++ know how many
> destructors to invoke? I'll investigate in the A.R.M. (The new
> Annotated Reference Manual by Ellis & Stroustrup). Is this an issue
> for us (i.e., do PrimArrays need it?)
In ordinary c environments, heap-allocated (malloc()ed) storage starts
with a small struct, and the pointer returned from the allocator points
to the memory just beyond this struct. The struct holds information
about the size of the memory, for use by free().
I see no reason C++ shouldn't use exactly the same trick to keep a count
of how many objects need to be destroyed in an array of objects.
In 2.0, at least, storage for arrays of Foo objects is obtained, not
through the Foo::operator new(), but through the global ::operator new().
Even if you force the use of Foo::operator new() by using the syntax
::new(), C++ supplies Foo::operator new() with the size of the region
it is to allocate, and there's nothing to prevent it from adding space
to scribble down a count.
michael