In an attempt to build a matrix on my small computer, the array size becomes big, it goes out memory capacity and then I got a segv, I want to know if there a way in C++ to detect segv without jumping out and then continue?
unsigned m = 10000;
unsigned n = 10000;
double mat[m][n];
for (unsigned i = 0; i < m; ++i)
{
for (unsigned j = 0; j < n; ++j)
{
double tmpNum1 = rand()%precisionA;
double tmpNum2 = tmpNum1/precisionA+rand()%precisionB;
mat[i][j] = tmpNum2;
}
}
if (segv) // How to do this???
{
cout<< "Buy a new computer please!" << endl;
}
else
{
cout<< "Good, get a coffee for yourself!" << endl;
}
Edit1: Sometimes the error is segv, sometimes it is "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)"
Edit2: Using Ubuntu here.