As Kevin notes in his comment, the problem is not RAM, but the stack. You allocate an array of 10 million items on the stack when you really need to allocate it on the heap using friends of malloc et. Even in C, this causes a segmentation error:
int main(void) { int array[10000000]; array[5000000] = 1; return 0; } $ gcc -O0 bigarray.c #-O0 to prevent optimizations by the compiler $ ./a.out Segmentation fault (core dumped)
While:
#include <stdlib.h> int main(void) { int *array; array = malloc(10000000 * sizeof(int)); array[5000000] = 1; return 0; } $ gcc -O0 bigarray2.c $ ./a.out $ echo $? 0
source share