Article View: comp.std.c++
Article #3841Re: Placement delete suggestion Keywords: delete placement
From: Dietmar Kuehl
Date: Wed, 27 Mar 1996 23:41
Date: Wed, 27 Mar 1996 23:41
35 lines
2864 bytes
2864 bytes
Hi,
Fergus Henderson (fjh@munta.cs.mu.OZ.AU) wrote:
: Or is it? On second thoughts, I think the work-around suggested in the ARM
: of using a my_delete function won't work for array delete, since you
: don't know how many elements to delete. That is rather unfortunate --
: it certainly limits the usefulness of placement array new.
OTOH, as Tim Hollebeek observed in a thread in comp.lang.c++.moderated
(Placement new and arrays), the usefulness of placement array new is
limited anyway: There is no portable way to figure out how much
"allocation overhead" there will be and thus it is impossible to
predict how much memory has to be set aside for a placement array new.
In fact, it turns out that it is impossible to place an array at a
specific address with placement new due to this allocation overhead:
See the example in expr.new verse 12 of the April DWP: "... - 'new(2,f)
T[5]' results in a call of 'operator new[](sizeof(T)*5+y,2,f)'. Here,
'x' and 'y' are non-negative, implementation-defined values
represeneting array allocation overhead. They migh vary from one use of
'new' to another.". There is nothing said about the address of the
first element of the array... The only portable way I know to place an
array at a specific address in a chunk of memory whose size can be
predicted, is to do it "by hand", i.e. using placement (non-array) new
for each individual element of the array (and, of course, using
explicit destructor calls to release the objects).
--
dietmar.kuehl@uni-konstanz.de
http://www.informatik.uni-konstanz.de/~kuehl
I am a realistic optimist - that's why I appear to be slightly pessimistic
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<4jc296$h0t@news.BelWue.DE>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernReferences:
<4j4ec5$d41@fsgi01.fnal.gov> <9603261124.AA22276@lts.sel.alcatel.de> <4jboij$4t3@mulga.cs.mu.OZ.AU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl) Newsgroups: comp.std.c++ Subject: Re: Placement delete suggestion Keywords: delete placement Date: 27 Mar 1996 15:41:05 PST Organization: Fakultät für Mathematik und Informatik Approved: austern@isolde.mti.sgi.com Message-ID: <4jc296$h0t@news.BelWue.DE> References: <4j4ec5$d41@fsgi01.fnal.gov> <9603261124.AA22276@lts.sel.alcatel.de> <4jboij$4t3@mulga.cs.mu.OZ.AU> Reply-To: dietmar.kuehl@uni-konstanz.de NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 27 Mar 1996 18:43:50 GMT X-Newsreader: TIN [version 1.2 PL2] X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMVnSEky4NqrwXLNJAQFN2AH/Z22DzlQ4DbWL8898JZcLRSlcaD2cen8X d6+KyOsBTp9Ug2vpw5KhOG2tIMGL3IdoXZeRStoIWsGnjxAOWZuIpw== =/P/X Originator: austern@isolde.mti.sgi.com