[Patch] stl_vector.h
Paolo Carlini
pcarlini@suse.de
Wed Oct 13 00:19:00 GMT 2004
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.
>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 ;)
Paolo.
More information about the Libstdc++
mailing list