Topic: placement delete syntax [was "operator delete" should be a template]


Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Mon, 24 May 2004 17:01:02 +0000 (UTC)
Raw View
Bo Persson wrote:
> "Alberto Barbati" <AlbertoBarbati@libero.it> skrev i meddelandet
>
>>I really don't know. In fact I was surprised as you are when I first
>>discovered this. I guess that it would be too easy to mismatch a
>>placement new with its placement delete, but it doesn't seem to be a
>>very compelling argument.
>
> I think the reason is as simples as: There is no need for it!

To clarify my position, I agree with you on this point. I was just
playing the role of the devil's advocate ;-)

> If you want to destroy the object pointed to by p, you just use the
> destructor for that object:
>
> p->~type();
>
> That destroys the object without deallocating any memory, alas a
> placement delete.

Placement delete *can* deallocate memory. Maybe you are associating the
term "placement delete" with "::operator delete(void*, void*)" that is
implemented as a no-op. Instead, I was referring to the terminology used
in 5.3.4/11 to describes *any* form of operator new/delete that has more
than one parameter (with one exception: operator delete(void*, size_t)
when there's no operator delete(void*)).

The issue is to have a delete-expression like syntax that both:

1) destroys the object (as in "p->~type()")
2) calls a user-defined deallocation function with more than one
parameter (as in "operator delete (p, arena)")

as it is defined in the current standard, the delete-expression does not
allow the additional parameters to be specified, so user-defined
deallocation functions with more than one parameter cannot be invoked by
a delete-expression.

As I said, I don't feel it very compelling to have such a syntax, as I
can think of more elegant ways to achieve the desired result. However, I
am wondering if there is a stronger rationale why the standard does not
provide it.

Alberto

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]