vector automatic growth size 
Author Message
 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.

I don't think you can configure how much it will grow, but
you can reserve() (pre-allocate) space in the vector.
Useful when you know beforehand how many elements you will add
to the vector.

The documentation also say that when the vector have to grow,
the reserved size (capacity()) always (at least) doubles.

--
Rune H. H. Huseby



Mon, 30 Apr 2001 03:00:00 GMT  
 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



Mon, 30 Apr 2001 03:00:00 GMT  
 vector automatic growth size
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.

regards,

Niels Hede Pedersen



Tue, 01 May 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. automatic destruction of items in vector

2. Runtime determination of automatic array size

3. Max size of automatic variables?

4. Minimum size of automatic store?

5. Automatic Array Size Determination

6. getting size of a vector via debugger

7. vector.size()

8. NW USA SOFTWARE C/C++ Famous Growth Company - design96.txt [1/1]

9. C growth.

10. Rapid growth of Access database file

11. Equation to predict the growth of hydrilla

12. Article: Developers, competitors say expansion of .Net strategy is aimed at suppressing growth of Java

 

 
Powered by phpBB® Forum Software