title: How do I create an array in C++ which is on the heap instead of the stack?
body: <p>I have a very large array which must be 262144 elements in length (and potentially much larger in future). I have tried allocating the array on the stack like so:</p>
  
  <pre><code>#define SIZE 262144
  int myArray[SIZE];
  </code></pre>
  
  <p>However, it appears that when I try and add elements past a certain point, the values are different when I try to access them. I understand that this is because there is only a finite amount of memory on the stack, as opposed to the heap which has more memory.</p>
  
  <p>I have tried the following without much luck (does not compile):</p>
  
  <pre><code>#define SIZE 262144
  int *myArray[SIZE] = new int[SIZE];
  </code></pre>
  
  <p>And then I considered using <code>malloc</code>, but I was wondering if there was a more C++ like way of doing this...</p>
  
  <pre><code>#define SIZE 262144
  int *myArray = (int*)malloc(sizeof(int) * SIZE);
  </code></pre>
  
  <p>Should I just go with <code>malloc</code>?</p>