Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: std::vector memory allocation (http://www.velocityreviews.com/forums/t267706-re-std-vector-memory-allocation.html)

tom_usenet 06-25-2003 02:33 PM

Re: std::vector memory allocation
 
On Wed, 25 Jun 2003 13:57:31 +0100, onion_skin
<onion_skin_RMV@travers.com> wrote:

>When a std::vector has to allocate more memory, am I correct in
>thinking that it allocates additional memory of equal size to the
>amount of memory required to store the existing number of elements?


No, it is implementation dependent, and it depends on why it has to
allocate memory (e.g. how many elements are being added, and how much
the current capacity is being exceeded by). In the case of a push_back
call, some implementations double the capacity, some use a different
factor, like 1.5, and some both double the size and add and extra bit
(like, say newcapacity = 2*currentcapacity + 5).

However, growth does have to be at least exponential to meet the
complexity guarantees.

Tom


All times are GMT. The time now is 02:27 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57