Topic: operator delete problem...
Author: miket@world.std.com (Michael Trachtman)
Date: Sat, 25 Jun 1994 18:15:44 GMT Raw View
Barry Margolin (barmar@think.com) wrote:
: In article <2to9v0$h5o@search01.news.aol.com> ericmi2848@aol.com (EricMi2848) writes:
: >We used the parameter capability of 'new' to allow for passing the
: >filename and line of an allocation.
: >But, when we went to look for this capability in the 'delete'
: >operator, it was missing.
: I've seen several messages asking about this in the past week. Why has
: this suddenly become such a hot issue?
: If you need the information at deletion time, why not store it in the class?
Because the original posting wanted to pass __FILE__ and __LINE__ to
the destructor. Presumably, in order to track memory use. I.e. to see
when memory gets allocated and when it gets freed. This information
(of when it gets freed) is obviously unavailable when the object
gets created.
Michael T.
Author: ssimpson@world.std.com (Steve Simpson)
Date: Mon, 27 Jun 1994 22:48:32 GMT Raw View
EricMi2848 (ericmi2848@aol.com) wrote:
: A coworker and I have been working on new memory management routines.
:
: We used the parameter capability of 'new' to allow for passing the
: filename and line of an allocation.
: But, when we went to look for this capability in the 'delete'
: operator, it was missing.
We overload 'new' in the same way. As others have pointed out, you're stuck
with the delete. If you want to know where the delete came from you can
do a stack trace. If you are writing Windows code, there is an article
written by one of the Borland programmers that gives the complete source
for a stack trace routine. The routine is w_assert written by Matt Pietrek.
The article was probably in Dr Dobbs or MSJ.
Steve Simpson | Never trust anyone whose suit is nicer
ssimpson@world.std.com | than your own.
Software Engineering Consultant | Quark
Author: davem@eden.rutgers.edu (David Miller)
Date: 28 Jun 94 14:32:40 GMT Raw View
John Max Skaller (maxtal@physics.su.OZ.AU) wrote:
: In article <2tshj1INNb4b@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
: >In article <2to9v0$h5o@search01.news.aol.com> ericmi2848@aol.com (EricMi2848) writes:
: >>We used the parameter capability of 'new' to allow for passing the
: >>filename and line of an allocation.
: >>But, when we went to look for this capability in the 'delete'
: >>operator, it was missing.
: >
: >I've seen several messages asking about this in the past week. Why has
: >this suddenly become such a hot issue?
: >
: >If you need the information at deletion time, why not store it in the class?
: Because operator delete is called AFTER the object is
: destroyed.
I think a lot of people have a problem realizing this very
point. Even from the perspective of simple class deletion it does not
know exactly what it is getting rid of. From the perspective of an
indirect virtual function call, it knows even less. Very few
assumptions can be made it.
Later,
David S. Miller
davem@eden.rutgers.edu
Author: ericmi2848@aol.com (EricMi2848)
Date: 15 Jun 1994 21:30:08 -0400 Raw View
A coworker and I have been working on new memory management routines.
We used the parameter capability of 'new' to allow for passing the
filename and line of an allocation.
But, when we went to look for this capability in the 'delete'
operator, it was missing.
for example:
you can do this:
void * operator new( unsigned size, char * filename, unsigned
linenumber );
and use it as
new ( __FILE__, __LINE__ ) foo;
unfortunately, this cannot be done:
void operator delete( void * pointer, char * filename, unsigned
linenumber );
and used as
delete( __FILE__, __LINE__ ) foo;
To me this seems to be non-orthogonal. Is there a reason for not
allowing this?
BTW: we looked for this in Stroustrup 2nd Ed. the ARM, and in the
Borland and Watcom compilers.
Thanx
Eric Miller
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Thu, 16 Jun 1994 18:24:33 GMT Raw View
ericmi2848@aol.com (EricMi2848) writes:
>unfortunately, this cannot be done:
>
>void operator delete( void * pointer, char * filename, unsigned
>linenumber );
>
>delete( __FILE__, __LINE__ ) foo;
>
>To me this seems to be non-orthogonal.
Yes, I agree.
>Is there a reason for not allowing this?
Yes. See the commentary in the ARM in the section on `delete'.
Also I guess D&E might well have some comments on it.
[But personally, I don't think the reasons mentioned there are
sufficiently persuasive, especially when you consider the issue in the
light of the problem of memory leaks caused by exceptions and
overloaded operator new.]
--
Fergus Henderson - fjh@munta.cs.mu.oz.au
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Thu, 16 Jun 1994 21:00:35 GMT Raw View
In article <2to9v0$h5o@search01.news.aol.com> ericmi2848@aol.com (EricMi2848) writes:
>
>A coworker and I have been working on new memory management routines.
>We used the parameter capability of 'new' to allow for passing the
>filename and line of an allocation.
>
>But, when we went to look for this capability in the 'delete'
>operator, it was missing.
>
>
>To me this seems to be non-orthogonal. Is there a reason for not
>allowing this?
Yes. The ARE non-orthogonal. 'new' requires a static
expression which determines the type of object constructed
exactly. The exact allocator and constructor are determined
statically.
Delete can be called through a base class subobject pointer
and dispatch via a virtual destructor occurs -- both the destructor
and delete to be used must be fixed at the point of construction/
allocation by new.
Multiple new operators must store information in the
memory extent allocated to allow the single delete operator
to select the correct operation dynamically. Only the
programmer of the allocators can do this, the person
calling the 'delete pointer' cannot know how the object
was constructed -- doesnt even know what type the object is.
Comment: think of 'delete' as a virtual non-static
member, because its used as if it were (via the destructor).
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA
Author: b91926@fsgi01.fnal.gov (David Sachs)
Date: 16 Jun 1994 16:29:31 -0500 Raw View
ericmi2848@aol.com (EricMi2848) writes:
>A coworker and I have been working on new memory management routines.
>
>We used the parameter capability of 'new' to allow for passing the
>filename and line of an allocation.
>But, when we went to look for this capability in the 'delete'
>operator, it was missing.
>for example:
>you can do this:
>void * operator new( unsigned size, char * filename, unsigned
>linenumber );
>and use it as
>new ( __FILE__, __LINE__ ) foo;
>unfortunately, this cannot be done:
>void operator delete( void * pointer, char * filename, unsigned
>linenumber );
>and used as
>delete( __FILE__, __LINE__ ) foo;
>To me this seems to be non-orthogonal. Is there a reason for not
>allowing this?
>BTW: we looked for this in Stroustrup 2nd Ed. the ARM, and in the
>Borland and Watcom compilers.
Unfortunately correct. The examples I have seen show that to
delete an object with a nonstandard placement you
1. Call the destructor of the object directly
2. Call whatever memory management routine is needed to free the
pace the object occupied.
yucch
Author: barmar@think.com (Barry Margolin)
Date: 17 Jun 1994 16:04:49 GMT Raw View
In article <2to9v0$h5o@search01.news.aol.com> ericmi2848@aol.com (EricMi2848) writes:
>We used the parameter capability of 'new' to allow for passing the
>filename and line of an allocation.
>But, when we went to look for this capability in the 'delete'
>operator, it was missing.
I've seen several messages asking about this in the past week. Why has
this suddenly become such a hot issue?
If you need the information at deletion time, why not store it in the class?
--
Barry Margolin
System Manager, Thinking Machines Corp.
barmar@think.com {uunet,harvard}!think!barmar
Author: cbarber@bbn.com (Christopher Barber)
Date: 17 Jun 1994 17:51:34 GMT Raw View
>>>>> "BM" == Barry Margolin <barmar@think.com> writes:
BM> In article <2to9v0$h5o@search01.news.aol.com> ericmi2848@aol.com
BM> (EricMi2848) writes:
>> We used the parameter capability of 'new' to allow for passing the
>> filename and line of an allocation. But, when we went to look for
>> this capability in the 'delete' operator, it was missing.
BM> I've seen several messages asking about this in the past week. Why
BM> has this suddenly become such a hot issue?
BM> If you need the information at deletion time, why not store it in
BM> the class?
Because you can't do this for datatype that has no class, i.e. fundamental
types such as int and char. Also, you can't do this for classes which you
may not modify for some reason.
- Chris
--
Christopher Barber
(cbarber@bbn.com)
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Fri, 17 Jun 1994 20:05:29 GMT Raw View
In article <2tshj1INNb4b@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
>In article <2to9v0$h5o@search01.news.aol.com> ericmi2848@aol.com (EricMi2848) writes:
>>We used the parameter capability of 'new' to allow for passing the
>>filename and line of an allocation.
>>But, when we went to look for this capability in the 'delete'
>>operator, it was missing.
>
>I've seen several messages asking about this in the past week. Why has
>this suddenly become such a hot issue?
>
>If you need the information at deletion time, why not store it in the class?
Because operator delete is called AFTER the object is
destroyed.
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA