This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Sizes when sizeof(value_type) == 1 (Was: Re: vector<> can...)
On Tue, 2004-10-19 at 16:21, Paolo Carlini wrote:
> 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!
Yes, this pesky case *does* remain as a bug, and I have mentioned in my
previous email:
"Even otherwise IMHO.
We *should* have a check that __len > __old_size everywhere."
However, regarding the policy for reallocating wherein we have different
forms like __old_size*2 and __old_size+max(...) that is perfectly fine.
Only the extra check needs to go there.
This problem would be solved partially IMHO with the patch I'm about to
send.
>
> 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