vector<> can probably never grow to it's maximum size!
chris
caj@cs.york.ac.uk
Wed Oct 20 15:24:00 GMT 2004
Dhruv Matani wrote:
>Yes, but isn't it better to have the container grow somehow rather than
>have it throw bad_alloc even though it can grow by whatever little it
>can in situations where the memory available is low.
>
>
>
As has I think been said before, on this particular point I would have
to say no, it's not better. In order to be a satisfying implementation,
the size has to continue growing exponentially. One way around this
would be to say that you are going to make sure the container grows to
at least (say) 105% of it's original size, else you don't bother. In
most cases I imagine that if you can't grow a structure by at least that
much, then probably the tiny amount extra you could provide isn't going
to be worth it, and as long as you fix some fraction you promise to grow
by, then you still remain within the standard (although possibly still
quite inefficent)
The other option of course is to only do this kind of 'low memory'
growth once, although that would then require some kind of extra flag.
Chris
More information about the Libstdc++
mailing list