This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: vector<> can probably never grow to it's maximum size!


On Wed, 2004-10-20 at 20:56, Paolo Carlini wrote:
> 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.
> >  
> >
> No, it isn't. Maybe other are willing to comment...

Yes, I would like to know what others too think about this. As Chris has
already mentioned about the guarantee that the library provides about
growing exponentially. And we should stick to that. He has a point
there. However, if you think from a user's point of view, if he says.
Hey, I asked for adding just 1 element, and it's throwing! You may say
Buddy, you should have used reserve!

Maybe some more comments would help here.

> 
> In my opinion, you cannot *always* consider growing 1-item-at-a-time only
> because ::operator new throws. As I already told you, from the point of view
> of the user, that knows nothing about memory and so on, the vector is 
> growing
> slowly and since you are catching the exceptions he cannot know why.

Hmmm. The user may also start wondering why the vector is performing so
many copies. Maybe if the proposal is accepted in general, we can work
out some sort of upper limit(not 1 more element) that the vector hould
request as a last resort?


> 
> In my opinion, you can only repair a single throw in low memory, when 
> the size
> exceeds a defined limit (which depends on *many* factors, related to the
> architecture, the amount of installed mem, the number of running processes,
> and so on).
> 
> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]