This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: vector<> can probably never grow to it's maximum size!
Dhruv Matani wrote:
Actually, I think this would be useful after all. Consider the situation
where th vector already has 1.2GB of memory, and wishes to expand more.
Consider that the user does a push_back(). Now, the vector will try to
allocate 1.2*2=2.4GB of memory. Currently, I think Linux supports only
3GB data segment(heap) max.
Why are you always considering only 32-bit machines?
The push_back will throw even though it could have succeeded!
With the patched allocator, it will now try to allocate slightly more
than 1.2GB, and will succeed. Thus, we have presented a
function(push_back) from failing.
The point is not that doesn't make sense not doubling the request in low
memory (perhaps, you have to add limits, platform dependent...). The
point is
that you do *not* detect that condition via the arithmetic overflow
mechanism!
In the case you present above, __old_len * 2 = 2.4 GB, which does *not*
overflow 2^32 - 1. Therefore, your patch is flawed in any case.
Also, about the *small* allocations, are you aware of the fact that the old
SGI allocator had a 'reallocate' extension? Before devising newer, complex,
things, shouldn't we learn from that?
Paolo.