title: C++ Efficient Growing Vector of Fix-Sized Vector
body: <p>In my program, I had a <code>std::vector&lt;std::array&lt;float, n_channels&gt;&gt; vecvec</code>, where <code>n_channels</code> was a constant integer known at compile time.  In the program, <code>vecvec</code> grows over time.  </p>
  
  <p>I now want to lift the constraint that <code>n_channels</code> must be known at compile time, so I changed the definition to <code>std::vector&lt;std::vector&lt;float&gt;&gt; vecvec</code>.    <code>n_channels</code> is still a fixed value, which is known before <code>vecvec</code> is constructed (all elements of <code>vecvec</code> have the same length).  </p>
  
  <p>However, now my program is suddenly about 2.5x slower.  </p>
  
  <p>I assume this is because the memory of <code>vecvec</code> is suddenly fragmented, because it doesn't "know" that every element of vecvec will have the same size.  </p>
  
  <p>Is there a way I can have my cake and eat it too?</p>