title: Memory issues with a very large array in C++
body: <p>Hi I have the following:</p>
  
  <pre><code>struct myStructure
  {
   vector&lt;int&gt; myVector;
  };
  myStructure myArray[10000000];
  </code></pre>
  
  <p>As you can see I have a very large array of a vectors. The problem is that i dont have a priori knowledge of the number of elements I need to have in the array, but I know that 10 million elements is the max i can have. I have tried two things:</p>
  
  <p>a) make myArray a global array, however the problem is that i have a function that will access myArray many many times, which is resulting in memory leaks and the program crashing for large calculations.</p>
  
  <p>b) declare myArray dynamically from within the function that needs to access it, the memory is kept in check but the program runs about 8 times slower. </p>
  
  <p>Any ideas on how to address this issue. Thanks</p>