问题
in my C program, when I am taking an array like this
int a[100000][100000];
I am getting segmentation fault. Now if I am using array of size less than 1000 * 1000 , like this
int a[1000][1000];
I am not getting any problem.In my program I need to use a 10^5 * 10^5 array. What should I do to fix it .
回答1:
Dynamically allocate it with malloc. By declaring it statically you use the stack, which has a maximum size that the heap (used in dynamic allocations) does not.
int *pointer = malloc (sizeof (*pointer) * (100000*100000));
Then, to access it, use indices to represent the x and y coordinates.
来源:https://stackoverflow.com/questions/23472913/the-largest-size-of-2-d-array-in-c