Topic: Overloading operator delete


Author: feathers@serss0 (Michael Feathers)
Date: Wed, 6 Jan 1993 03:20:00 GMT
Raw View
I discovered the hard way a while ago that the operator delete can not be
overloaded in C++.

I've read the annotation in the ARM and I can not say that I agree with
the reasoning.  One example given for overloading operator new involves using
another arena for allocation.  But how will this memory be deallocated?

Doesn't the possibility of using the global delete accidently make the
absence of an overloadable delete at least as "hazardous" as allowing it?

I understand that there are many applications in which programmers may not
be concerned with reclaiming memory, but aren't there enough to justify being
able to use operator delete symmetrically with operator new without resorting
to the work around discussed in the ARM?

The work around that I've choosen involves using a set of malloc/free type
functions since I have no means of using an overloaded delete symmetrically
with an overloaded new.

Michael Feathers   [feathers@fiu.edu]


















Author: feathers@serss0 (Michael Feathers)
Date: Wed, 6 Jan 1993 12:12:54 GMT
Raw View
I am the author of this article.  I just realized that I did not explain
thoroughly.

In article <C0Ex9D.Ct7@fiu.edu> feathers@serss0 (Michael Feathers) writes:
>
>I discovered the hard way a while ago that the operator delete can not be
>overloaded in C++.

That is, overload operator delete with the placement syntax.  We can provide
extra versions of operator new with an arbitrary number of additional
arguments, but there can be no additional arguments to delete other than
those specified in the ARM.

I don't have the ARM at home with me right now, so I can not recite chapter
and verse.

>I've read the annotation in the ARM and I can not say that I agree with
>the reasoning.  One example given for overloading operator new involves using
>another arena for allocation.  But how will this memory be deallocated?
>
>Doesn't the possibility of using the global delete accidently make the
>absence of an overloadable delete at least as "hazardous" as allowing it?
>
>I understand that there are many applications in which programmers may not
>be concerned with reclaiming memory, but aren't there enough to justify being
>able to use operator delete symmetrically with operator new without resorting
>to the work around discussed in the ARM?
>
>The work around that I've choosen involves using a set of malloc/free type
>functions since I have no means of using an overloaded delete symmetrically
>with an overloaded new.
>
>Michael Feathers   [feathers@fiu.edu]
>
>

Michael Feathers [feathers@fiu.edu]