Sunday 6 September 2015

Getting segmentation fault due to array size limit. Try this !

 Use static keyword:
Code:
static int i[2000][2000]; 
Without doing it, it goes to the heap, which is limited in size by the linker (can be something like 1 megabyte) and is not suitable for storing large variables.

Be aware that your function is no more reentrant after that.

or

Assign Dynamic allocation to array:
 

Code:
int **array=malloc(2000*2000*sizeof(int));
or something similar. or use the fancy "new" keyword in C++.

(for those who say malloc is not C++ enough, that may be true, but it's still functional)

No comments:

Post a Comment