[Patch] stl_vector.h

Dhruv Matani dhruvbird@gmx.net
Wed Oct 13 03:48:00 GMT 2004


On Wed, 2004-10-13 at 05:48, Paolo Carlini wrote:
> Dhruv Matani wrote:
> 
> >Exactly, so a standard compliant allocator (user defined though) may do
> >weird stuff if n==0! We may not rely on such behaviour.
> >  
> >
> I don't read very often in the standard the word "weird" ;)

:-)

> Seriously, the standard says only that "the return value is 
> unspecified", not that
> allocate can throw, or whatever. A standard compliant allocator shall 
> return *any*
> value, even zero, really "weird" value indeed, which is also ok.

Ok, if that's the case, then we should be quite well off. I was always
under the impression that allocate(0) was one of those grey areas, and
implementations were to to any ["weird" stuff ;-)] when it happened,
like throw an exception or something like that. But since that is not
the case, I was obviously wrong the first time round.

> 
> >Strictly, speaking then we *MUST* call deallocate for every such
> >allocate(0) call or it will be a faulty library(memory leak).
> >  
> >
> Indeed we do, whenever the first argument of _M_deallocate != 0, since 
> it's, say,
> "unlikely" ;) that the allocator leaks memory allocated at address zero ;)

Yes, leaks at address 0 are not possible!

> 
> Paolo.
-- 
        -Dhruv Matani.
http://www.geocities.com/dhruvbird/

The price of freedom is responsibility, but it's a bargain, because
freedom is priceless. ~ Hugh Downs



More information about the Libstdc++ mailing list