🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

4 total messages Started by Robert Martin Mon, 18 Sep 1995 21:31
placement delete
#1987
Author: Robert Martin
Date: Mon, 18 Sep 1995 21:31
40 lines
2080 bytes
Question:

It is my understanding from the WP that placement versions of operator
delete are only called when a constructor of a object created by the
corresponding placment new throws an exception.  I have seen this
confirmed by a recent thread in this newsgroup.

That thread also suggested that the only way to explicitly call
placement delete would be to overtly call the appropriate operator
delete.  e.g.

	operator delete (object, arg1, arg2);

Now, as I understand it, such a call will not cause the destructor of
the object to be called.  Thus, of one is to invoke the placement
syntax of operator delete, one must first explicitly call the
destructor.  e.g.

	object->X::~X(); // destruct
        operator delete(object, arg1, arg2); // deallocate

If, in a certain application, placement delete *must* be conjugated
with placement new, then all objects must be separately destructed and
deleted as above; there is no single statement equivalent to
'delete(arg1, arg2) object' that will coordinate the destruction and
deletion.  

Is this correct?  If so, does the committee feel that this represents
a weakness in the language that will be addressed in the standard?
-- 
Robert Martin       | Design Consulting   | Training courses offered:
Object Mentor Assoc.| rmartin@oma.com     |   OOA/D, C++, Advanced OO
2080 Cranbrook Rd.  | Tel: (708) 918-1004 |   Mgt. Overview of OOT
Green Oaks IL 60048 | Fax: (708) 918-1023 | Development Contracts.

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: placement delete
#1988
Author: Sam Fenster
Date: Tue, 19 Sep 1995 01:33
16 lines
1310 bytes
rmartin@rcmcon.com (Robert Martin) writes:
> That thread also suggested that the only way to explicitly call placement
> delete would be to overtly call the appropriate operator delete.  e.g.
> 
> 	operator delete (object, arg1, arg2);

In fact, wouldn't you have to call `operator delete' with the address of the
most derived subclass object?  How would you do that?

> Now, as I understand it, such a call will not cause the destructor of the
> object to be called.  Thus, of one is to invoke the placement syntax of
> operator delete, one must first explicitly call the destructor.
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: placement delete
#1996
Author: Bill Gibbons
Date: Wed, 20 Sep 1995 08:38
23 lines
1272 bytes
In article <FENSTER.95Sep18204129@shadow.cs.columbia.edu>,
fenster@cs.columbia.edu (Sam Fenster) wrote:
> rmartin@rcmcon.com (Robert Martin) writes:
> > That thread also suggested that the only way to explicitly call placement
> > delete would be to overtly call the appropriate operator delete.  e.g.
> > 
> >       operator delete (object, arg1, arg2);
> 
> In fact, wouldn't you have to call `operator delete' with the address of the
> most derived subclass object?  How would you do that?

     operator delete (dynamic_cast<void*>(object), arg1, arg2);

-- 
Bill Gibbons
bgibbons@taligent.com


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: placement delete
#2006
Author: J. Kanze
Date: Fri, 22 Sep 1995 17:09
59 lines
2583 bytes
kanze (kanze@lts.sel.alcatel.de) wrote:

|> The other case is managing different pools of memory, perhaps using
|> different strategies.  In this case, as far as I can see, the user
|> must also provide a non-placement form for new and delete; the normal
|> forms will *not* work.  It is up to the delete to somehow figure out
|> which strategy to use to free the memory, given only its address.

Since posting the above, an idea on how to solve this using mixins has
occurred to me.

Consider the following:

	class Pool1
	{
	public :
		void*				operator new( size_t ) ;
		void				operator delete( void* ) ;
		virtual				~Pool1() {}
	} ;

	//	Other pools the same.

	class Buffer { /* ... */ } ;

	class BufferInPool1 : public Buffer
						, public Pool1
	{
		//	Eventually, constructors, since they are not inherited
	} ;

	Buffer*				p1 = new Buffer ;
	Buffer*				p2 = new BufferInPool1 ;
	//  ...
	delete p1 ;							//	should use global delete
	delete p2 ;							//	uses delete for Pool1

I believe that the above is legal, and will work as expected if Buffer
has a virtual destructor.  It also offers a portable solution to
determining which pool is used in the destructor, and allows defining
operator new for specific pools without also having to define the normal
operator new.

The only problem I see is that I suspect that the most frequent use of
distinct pools is shared memory, and in general, virtual functions don't
work in shared memory:-(.  (Since this is comp.STD.c++, however, and the
standard says nothing about shared memory, we can ignore this problem
here:-).)
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle--
                             --Beratung in industrieller Datenverarbeitung

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads