title: Calculating size of vector of vectors in bytes
body: <pre><code>typedef vector&lt;vector&lt;short&gt;&gt; Mshort;
  typedef vector&lt;vector&lt;int&gt;&gt; Mint;
  
  Mshort mshort(1 &lt;&lt; 20, vector&lt;short&gt;(20, -1)); // Xcode shows 73MB 
  Mint mint(1 &lt;&lt; 20, vector&lt;int&gt;(20, -1)); // Xcode shows 105MB
  </code></pre>
  
  <p>short uses 2 bytes and int 4 bytes; please note that <code>1 &lt;&lt; 20 = 2^20</code>;</p>
  
  <p>I am trying to calculate ahead (on paper) usage of memory but I am unable to. </p>
  
  <pre><code>sizeof(vector&lt;&gt;) // = 24 //no matter what type
  sizeof(int) // = 4
  sizeof(short) // = 2
  </code></pre>
  
  <p>I do not understand: <code>mint</code> should be double the <code>mshort</code> but it isn't. When running program only with <code>mshort</code> initialisation <strong>Xcode shows 73MB of memory usage; for <code>mint</code> 105MB</strong>;</p>
  
  <pre><code>mshort.size() * mshort[0].size() * sizeof(short) * sizeof(vector&lt;short&gt;) // = 1006632960
  mint.size() * min[0].size() * sizeof(int) * sizeof(vector&lt;int&gt;) // = 2013265920
  
  //no need to use .capacity() because I fill vectors with -1
  1006632960 * 2 = 2013265920
  </code></pre>
  
  <p>How does one calculate how much space of RAM will 2d <code>std::vector</code> use or 2d <code>std::array</code> use.</p>
  
  <p>I know the sizes ahead and each row has same number of columns.</p>