Sizes when sizeof(value_type) == 1 (Was: Re: vector<> can...)

Paolo Carlini pcarlini@suse.de
Tue Oct 19 11:01:00 GMT 2004


Dhruv Matani wrote:

>I don;t think so. It seems fine to me.
>
Let's consider just a series of push_back: every time you reallocate,
the size doubles (in _M_insert_aux), and this gives problems as soon
as you reach ~ half max_size.

Ok, a simple example with an hypothetical 16-bit machine: in this case,
max_size = 65535 (we are always working with sizeof(vale_type) == 1).

When __old_size = 32768, _M_insert_aux computes __old_size * 2, which
is *exactly zero*, since overflows the max rapresentable number by one!

You could easily ask the allocator whatever in the range [__old_size + 1,
2 * __old_size - 1], and instead you are asking exactly zero!

Stra-bummer!

Paolo.



More information about the Libstdc++ mailing list