
vector automatic growth size
Quote:
>How can I control the size of the chunks by which a stl::vector grows
>automatically ?. I want something like the GrowBy parameter of MFC
>CObArray::SetSize member. Having a vector grow by only one element each time
>can't be right.
std::vector grows geometrically if you're using push_back() or insert().
This means it at least doubles its size when it needs to grow. You can
defeat this policy by preceding an insertion with a call to reserve().
There's no way to set a "growth increment"; growing by a fixed number of
elements can result in very poor performance if there are a lot of
reallocations, so it's no great loss, especially since you can still achieve
this effect by using reserve().
--
Doug Harrison