title: C++ large multidimensional-arrays on stack
body: <p>My simulation tries to predict the demand on a system for a long period of time ... the output results in a very large 4D array (I use the 4 dimensions to minimise the chance of an error when the data is written to the array i.e. I can understand it better this way!).</p>
  
  <p>The array size will be 25x4x3x20000 and I need it to be at least an (unsigned int) but I know that the stack can't handle this amount of data. </p>
  
  <pre><code>unsigned int ar[25][4][3][2000];
  </code></pre>
  
  <p>I have been looking around and found different solutions. However I am still undecided on which one to implement. So my question is: which one is better in term of performance and good practice:</p>
  
  <ol>
  <li><strong>Use a vector of arrays:</strong> as described in <a href="https://stackoverflow.com/questions/18991765/vector-of-vectors-reserve">stackoverflow.com/questions/18991765</a> ... But then any idea on how to convert for a 4D dimensions? </li>
  </ol>
  
  <blockquote>
    <p><code>std::vector&lt; std::array&lt;int, 5&gt; &gt; vecs;
    vecs.reserve(N);</code></p>
  </blockquote>
  
  <ol start="2">
  <li><strong>Use a 4D vector and push_back()</strong>: I didn't use this because I know the final size of the array and I wanted to prevent many push_backs operations. </li>
  <li><strong>Create the array on the heap</strong>: as described in 
  <a href="https://stackoverflow.com/questions/675817/how-do-i-create-an-array-in-c-which-is-on-the-heap-instead-of-the-stack">stackoverflow.com/questions/675817</a></li>
  </ol>
  
  <p>Any other suggestion is appreciated!</p>