title: Why does vector pointers takes so much memory?
body: <p>I'm working on a project where I need to be as mean as possible regarding the memory usage. I'm trying to calculate the grand total size of a <code>vector&lt;bool&gt;</code> of size <code>32</code> in the example:</p>
  
  <pre><code>vector&lt;bool&gt; v(32);
  cout &lt;&lt; "sizeof: " &lt;&lt; sizeof(v) &lt;&lt; endl;
  cout &lt;&lt; "size: " &lt;&lt; v.size() &lt;&lt; endl;
  cout &lt;&lt; "capacity: " &lt;&lt; v.capacity() &lt;&lt; endl;
  cout &lt;&lt; "max_size: " &lt;&lt; v.max_size() &lt;&lt; endl;
  </code></pre>
  
  <p>which gives me:</p>
  
  <pre><code>sizeof: 40                     &lt;- 40 byte? wtf?
  size: 32                       &lt;- hoping an element takes up 1 bit
                                    (instead of the usual 1 byte for booleans)
                                    this should take around 32 bit memory
  capacity: 64                   &lt;- I guess this is because minimum size is
                                    1 integer = 64 bit
  max_size: 9223372036854775744  &lt;- relevant somehow?
  </code></pre>
  
  <p>on my 64 bit ubuntu 12.04 machine. So I thought I could calculate the memory like so:</p>
  
  <pre><code>40 * 8 + 64 * 1 = 384 bit = 48 byte
  </code></pre>
  
  <p>So according to this calculation most of the memory is spent for the vector object of size <code>32</code>. My question is why does a <code>vector</code> object need to use so much memory? And also are there any mistakes in my calculation? How can I be more efficient without doing bitwise manipulations myself for vector sizes around <code>32</code>?</p>