I want to have an array, grid[50000][50000], i tried to do with vector but when i run the code, it stops. No error. Just waits.Any suggestions?
#include <iostream>
#include <vector>
using namespace std;
typedef std::vector<int> IntVec;
typedef std::vector<IntVec> IntGrid;
IntGrid grid(50000, IntVec(50000));
int main(){
grid[0][0]=3;
cout<<grid[0][0]<<endl;
}
As a very rough calculation,
50,000 rows × 50,000 columns × 4 bytes/integer =
10,000,000,000 bytes.Unless your computer has more than 10 GB of RAM, you’ve run out of memory.
Can you rewrite your program to work with smaller chunks of data, or to use a file to store the parts of the array that don’t require immediate access?