 <p>Use a different data structure. I'd suggest trying something like one of the <a href="http://www.boost.org/doc/libs/1_39_0/libs/numeric/ublas/doc/matrix_sparse.htm" rel="nofollow">sparse matrix classes from Boost</a>. They are optimised for storing numeric data in which each row or column contains a significant number of zeroes. Mind you, if the problem you're trying to solve isn't suitable for handling with a sparse data structure, it would be a good idea to set out the nature of the problem you're trying to solve, in greater detail. Take another look at <a href="http://stackoverflow.com/questions/how-to-ask">http://stackoverflow.com/questions/how-to-ask</a> even though I guess you already read that.</p> <p>But before you do that I think you probably have another problem too:</p> <blockquote> <p>access myArray many many times, which is resulting in memory leaks and the program crashing for large calculations</p> </blockquote> <p>It looks to me from what you write there that your code may have some pre-existing bugs. Unless your crashes are simply caused by trying to allocate a 10000000-element array as an <code>auto</code> variable.</p>