From 5448726611484239400
X-Google-Thread: f78e5,574518e5c7a60feb
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news3.google.com!news.glorb.com!koehntopp.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.vmunix.org!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: phalpern@halpernwightsoftware.com (Pablo Halpern)
Newsgroups: comp.std.c++
Subject: Re: Revised Allocator Proposal
Date: Thu,  1 Sep 2005 05:44:07 GMT
Organization: EarthLink Inc. -- http://www.EarthLink.net
Lines: 44
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <ur9bh1p2f68nk2o7ntdct1iblcrj5t8h2e@4ax.com>
References: <7ibbe1hu4omoqsfibanas46idf9u6i5hjo@4ax.com> <r5msg19kp6bearr4j87ijafhjgqafpd62r@4ax.com> <pan.2005.08.29.15.57.18.316344@marlowa.plus.com>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.demon.co.uk 1125553454 9288 158.152.254.254 (1 Sep 2005 05:44:14 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 1 Sep 2005 05:44:14 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
X-Path: comp-std-cpp-robomod!not-for-mail
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id j815i7Dn015172;
	Thu, 1 Sep 2005 15:44:07 +1000 (EST)
X-NNTP-Posting-Date: Wed, 31 Aug 2005 06:02:15 PDT
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Newsreader: Forte Agent 1.93/32.576 English (American)
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:1986

public@marlowa.plus.com (Andrew Marlow) wrote:

>It is not clear to me exactly why wherever you have an allocator parameter
>it tends to be a pointer rather than a reference. Why is that please? Will
>the proposal specify what the behaviour is when the pointer is null?

In general, it is easiest to construct an allocator object from a class
derived from allocator_implementation.  The automatic conversion from
allocator_implementation* to allocator<T> does the rest.  For example,
given a region allocator declaration:

    class region_allocator : public std::allocator_implementation {...};

It is simpler to write:

    region_allocator myAlloc;
    vector<int> myVector(&myAlloc);

than it is to write the equivalent:

    region_allocator myAllocImp;
    std::allocator<int> myAlloc(&myAllocImp);
    vector<int> myVector(myAlloc);

Being pedantic, region_allocator should really be named
region_allocator_implementation.  However, once you start using this
style of allocator, you start thinking of the implementation class as
the actual allocator, with std::allocator<T> being just a wrapper for
backwards compatibility.  By passing in a pointer to the implementation
class object, we also make it explicit that only the pointer is being
copied, not the entire implementation object.

Thanks for asking.

Pablo Halpern                 phalpern@halpernwightsoftware.com
Author: The C++ Standard Library from Scratch
http://www.halpernwightsoftware.com/stdlib-scratch

---
[ 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                       ]



