From 7756342280557641278
X-Google-Thread: f78e5,574518e5c7a60feb
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news2.google.com!newsfeed.gamma.ru!Gamma.RU!colt.net!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: gcarlton@iinet.net.au (Geoff Carlton)
Newsgroups: comp.std.c++
Subject: Re: Revised Allocator Proposal
Date: Fri, 29 Jul 2005 16:42:06 GMT
Lines: 75
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <42e9e832$0$5429$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
References: <7ibbe1hu4omoqsfibanas46idf9u6i5hjo@4ax.com> <hinnant-1BAC6A.16393526072005@syrcnyrdrs-01-ge0.nyroc.rr.com> <42e96769$0$5397$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <hinnant-72B4E1.21084528072005@syrcnyrdrs-03-ge0.nyroc.rr.com>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.demon.co.uk 1122655343 26044 158.152.254.254 (29 Jul 2005 16:42:23 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 29 Jul 2005 16:42:23 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913)
X-Accept-Language: en-us, en
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id j6TGg6T9001365;
	Sat, 30 Jul 2005 02:42:06 +1000 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-Delivered-To: std-c++@ucar.edu
X-Spamscanner: mailbox4.ucsd.edu  (v1.6 Apr  6 2005 07:48:50, 0.0/5.0 3.0.0)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Newsgroups: comp.std.c++
X-MailScanner: PASSED (v1.2.8 98845 j6T8QZQS015722 mailbox4.ucsd.edu)
Xref: g2news1.google.com comp.std.c++:1556

Hello,
Can I show a working example?  Good question!

I must admit I have never come across the case in the wild.  Swapping 
whole vectors is something that I do rarely, and optimising a subsystem 
using an allocator is similarly rare, so I've never yet seen an overlap.

Also after working around several examples, it is such an odd situation 
that its hard to argue a case in which it strikes.  Playing around with 
a short life expectant vector in such a way as swap is sort of like 
playing with fire.

The simplest example is of TinyXml (improved to use allocators), except 
for the fact that it doesn't use std containers and its std string is 
well encapsulated.  As such I'll have to give an example where the 
TiXmlNode's "value" string is publically accessable.

std::string replaceString;

void DoSomething(TiXmlNode* node)
{
	std::swap(node->value, replaceString);
}

void LoadData()
{
	// allocate in blocks of 1024 bytes and free at the end
	// all the tinyxml stuff is created using this allocator
	MultiPileAllocator myalloc(1024);
	
	{
		TiXmlDocument mydoc(&myalloc);
		mydoc.LoadFile("in.xml");
		DoSomething(mydoc.RootElement());
		mydoc.SaveFile("out.xml");
	}
}

Ok so here we create a structure of something, use it, then discard it. 
    The problem is inadvertantly exchanging allocators with objects of a 
different lifetime.

Interestingly many examples that I experimented with actually work fine 
in VS7.1, since their implementation only does the quick swap if the 
allocators are equal.

Geoff


Howard Hinnant wrote:

> Thank you for your thoughtful reply.
> 
> My concern is that an O(N) swap is not always correct.  Such a swap can 
> invalidate code which depends on a nothrow exception safety guarantee 
> (as shown in a previous post).
> 
> Would it be possible for you to post demo code that expresses your 
> concern?  I do want to understand it better.
> 
> -Howard
> 
> ---
> [ 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                       ]
> 

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



