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!


Dhruv Matani wrote:

2. You must have noticed that __mt_alloc<> allocates more memory than
required at times. We can take advantage of this fact, and include
support for this functionality within __mt_alloc::allocate(n, hint)
itself!


Even not considering the fundamental problem with the type of hint (see my
other message), I think there is something weird in your reasoning: when
vector wants to grow and calls allocator::allocate(n), aither n is <~ 128 bytes,
and a pool is involved, or the request is passed directly to ::operator new.
Therefore, mt_alloc either issues to the OS a *very* small memory request - to
refill one of its pools, of order 4K - or just returns what ::operator new returns.
In low memory, only the latter requests are problematic, and there is nothing
pool-allocation-specific in that: you just want to deal gracefully with an
::operator new that throws. An interesting topic, admittedly, but you don't need
the second argument of allocate for that!!!


Anyway, in thinking about these topics, be careful with the exponential grow
guarantee in the standard (I know you are already aware of that, but, to be
sure... ;) If allocator::allocate keeps on throwing, heaven knows why, therefore
vector doesn't obtain the amount of memory that really needs to grow quickly,
and *catches* the exceptions retrying with a smaller request, *the user of the
program* cannot see that something is going wrong, instead he sees only a non
conforming vector, growing too slowly.


Paolo.


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