I am trying to define a large dynamic size 2D array in C. When the array size is not very big (e.g. 20,000 x 20,000), memory allocation works perfectly. However, when the array size is greater than 50K x 50K memory allocation fails. Here is the sample code.
long int i = 0;
int **Cf = calloc(30000, sizeof *Cf);
for( i = 0; i < 30000; i++){
Cf[i] = calloc(30000, sizeof *(Cf[i]));}
The What is the maximum size of buffers memcpy/memset etc. can handle? post has explained why this issue occurs. However, it does not say what to do when you need large dynamic 2D arrays in your program. I am sure there should be an efficient way of doing this since many scientific applications need this feature. Any suggestion?