(This question is answered earlier but solution is not working or I am not able to understand it!!)
I want to use large size matrix of say 2^16*2^16.How to do that?
Here is code I used with malloc:
// nrows=2^16
// ncols=2^16
int **a_matrix = (int**) malloc (nrows *sizeof(int*));
for (int i=0; i<nrows;i++)
a_matrix[i]=(int*) malloc (ncols *sizeof(int));
enter code here
now when I try to access a_matrix[55000][55000] its giving segmentation fault
I increased stack size to unlimited(with some commands) but still its not working.:(
Is there any other way to do it?
Edit: I just want to store 1/0 so even bool will work.But in that case also same problem!
If you just want to store booleans, using a packed bit-array would reduce the storage far enough that it would probably work. In C++, you would use a
std::vector<bool>or astd::bitset; in C,gives you (if the
malloccall doesn’t fail) a pointer to an array of2^16arrays of2^16bits. To access a bit, useIt’s probably best to make that a function
or maybe a macro.