title: When does a std::vector reallocate its memory array?
body: <p>I can't find anything that gives a definitive answer. I was just curious if a std::vector reallocate its internal array only when it absolutely must or will it reallocate ahead of time in anticipation (so to speak).</p>
  
  <p>For example:</p>
  
  <pre><code>std::vector&lt;int&gt; myVector;
  for (int i = 0; i &lt; 1000; ++i) myVector.push_back(i);
  
  cout &lt;&lt; myVector.size() &lt;&lt; '\n'      // Gives 1000 as expected
       &lt;&lt; myVector.capacity() &lt;&lt; endl; // Gives 1024 which makes sense
  </code></pre>
  
  <p>If I continue to add elements, is there ever any chance that one of the next 24 items I add will change the capacity or will it only reallocate once I put in a 25th item?</p>
  
  <p>Note:</p>
  
  <p>I did run a test using gcc 4.4.3 under Linux, but and it seems like the reallocation is done "on-demand", but I was curious if I was just lucky or if there is something somewhere stating that this is expected behavior.</p>