Reputation: 145
I'm creating 2D arrays, with the structure of an static array with dynamic arrays. The code is below:
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
#define MAT_SIZE 100000
typedef float* DynMat[MAT_SIZE];
int main()
{
int r, c;
DynMat matDyn, matDynAns;
for (r = 0; r < MAT_SIZE; r++)
{
matDyn[r] = new float[MAT_SIZE];
matDynAns[r] = new float[MAT_SIZE];
for (c = 0; c < MAT_SIZE; c++)
{
matDyn[r][c] = 0;
matDynAns[r][c] = 0;
}
}
cout << "hello" << endl;
}
I believe there is a silent runtime error being thrown during my initialization of the matrices, because the code compiles and runs, yet nothing is printed.
Upvotes: 0
Views: 145
Reputation: 39778
Your program gradually allocates 80 GB of memory. It’s not printing anything because it’s swapping forever instead. (This is similar to thrashing, but instead of repeatedly loading a “few” pages it’s just linearly filling many of them.)
Upvotes: 2