From -6061367853876294288
X-Google-Thread: f78e5,99f1efda99846e15
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news2.google.com!proxad.net!news.cs.univ-paris8.fr!news.zanker.org!news.clara.net!wagner.news.clara.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!mutlu.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: do-not-spam-benh@bwsint.com (Ben Hutchings)
Newsgroups: comp.std.c++
Subject: Re: Custom allocator for vector
Date: Thu, 26 Aug 2004 00:05:26 GMT
Lines: 48
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <slrncipl0d.3d3.do-not-spam-benh@shadbolt.i.decadentplace.org.uk>
References: <2ns6efF45gptU1@uni-berlin.de> <5bp3i05gbil94hkm6je61ehubm3jv2om5d@4ax.com>
NNTP-Posting-Host: news.news.demon.net
X-Trace: news.demon.co.uk 1093478733 22842 158.152.254.254 (26 Aug 2004 00:05:33 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 26 Aug 2004 00:05:33 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: slrn/0.9.7.4 (Linux)
X-Spam-Checker-Version: SpamAssassin 2.64-mulga_r1 (2004-01-11) on 
	mulga.cs.mu.OZ.AU
X-Orig-X-Trace: news.uni-berlin.de B7BTaMdp/yaCcRrIPMGQeALlcgGF332BIU7JIJMK88TXMxqvs=
X-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham 
	version=2.64-mulga_r1
X-Reply-To: Ben Hutchings <benh@bwsint.com>
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i7Q05Qsj010362;
	Thu, 26 Aug 2004 10:05:26 +1000 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-Spam-Level: 
X-Delivered-To: std-c++@ucar.edu
X-Spamscanner: mailbox1.ucsd.edu  (v1.4 May 20 2004 13:55:33, 0.0/5.0 2.63)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Orig-Path: decadentplace.org.uk!nobody
X-Newsgroups: comp.std.c++
X-MailScanner: PASSED (v1.2.8 13506 i7PIFA4b013866 mailbox1.ucsd.edu)
Xref: g2news1.google.com comp.std.c++:2157

tom_usenet wrote:
> On Tue, 10 Aug 2004 17:18:53 GMT, alexvn@big-foot.com ("Alex Vinokur")
> wrote:
> 
>>Different compilers produce quite different behavior with the same
>>custom allocator.
>>
>>Here is the Nicolai M. Josuttis' allocator code sample (for vector)
>>with cosmetic changes added by me to profile the executable:
>>http://groups.google.com/groups?threadm=2nrba8F3sq7sU1%40uni-berlin.de
>>
>>Here are run log files for the following compilers
>>* GNU g++ : http://groups.google.com/groups?selm=2nrb31F3q19kU1%40uni-berlin.de
>>* Microsoft C++ : http://groups.google.com/groups?selm=2nrbdaF3orecU1%40uni-berlin.de
>>* Borland C++ : http://groups.google.com/groups?selm=2nrbe9F3ta94U1%40uni-berlin.de
>>
>>We can see that
>>* GNU g++ 3.3.1 doesn't invoke construct() and destroy();
>>* Microsoft C++ 13.00 and Borland C++ 5.5.1 do invoke construct()
>>  and destroy().
> 
> Unless your allocator is using a special type of pointer, I don't
> think an allocator should care whether construct() and destroy() are
> called or not, since the effects of those functions must be just to do
> a placement new and explicit destructor call.
> 
> For example, an obvious optimization for POD types is not to call the
> destroy function at all.
<snip>

Consider an allocator for a (conservatively) garbage-collected heap. 
When an object is destroyed but its memory is not deleted, any memory
that was referenced solely by it should not be considered reachable.
Therefore the object's memory should be cleared after its destructor
runs.  This can be done by the allocator's destroy() function,
dependent on the container invoking that function.

(Unfortunately I don't see a way for an allocator to tell whether or
not the object is going to be deleted after being destroyed, so there
is a trade-off between wasting memory by not clearing those pointers
and wasting time by clearing memory that's about to be freed.)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



