Largest Possible Array on My System

I want to use the largest possible 2D array that my system can manage in some code I am working on. Below is the code I used to try to achieve this.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
    int N=10000;
    vector< vector<int> > M(N, vector<int>(N));
    system("PAUSE");
    return EXIT_SUCCESS;
}


This code above runs just fine, but if I instead set N equal to 100000 (a larger number) then I get the error message:

"This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."

My question is, specifically why am I getting this error message? Is there any other way I can use a 2D array in c++ that is of a still greater size? And when I first saw this error I assumed I was getting this because I was at the limit beyond which my RAM could handle, but if so, would it be possible to store this 2D array M in the hardrive memory instead? And if so how would I do that in c++?
Last edited on
An 10000^2 int array is probably 381 MiB, ignoring memory fragmentation. 100000^2 int array requires 100 times as much memory, so that's 38.1 GiB.

Yes, it's possible to use the file system to store extremely large data structures and swap in and out of memory as required. AFAIK, the STL containers are not designed to do this, however. You'd need to implement your own vector class, or use an implementation that does have this feature.
Do you really need an array that large? Tell us about the problem you're trying to solve. I think you'll find that it can be solved without having to keep that much data in memory.
Topic archived. No new replies allowed.