Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: std::vector memory allocation

Reply
Thread Tools

Re: std::vector memory allocation

 
 
tom_usenet
Guest
Posts: n/a
 
      06-25-2003
On Wed, 25 Jun 2003 13:57:31 +0100, onion_skin
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An idea for heap allocation at near stack allocation speed Bjarke Hammersholt Roune C++ 14 03-06-2011 08:07 AM
static memory allocation versus dynamic memory allocation Ken C Programming 24 11-30-2006 12:37 AM
What is the difference between dynamic memory allocation,and stack allocation ? chris C++ 6 10-28-2005 05:27 AM
memory allocation and freeing memory Rodrigo Dominguez C Programming 11 06-14-2005 11:54 PM
Dynamic memory allocation and memory leak... s.subbarayan C Programming 10 03-22-2005 02:48 PM



Advertisments