Sunday, 3 July 2016

C - huge arrays - Segmentation fault (core dumped)

I'm getting the error "Segmentation fault (core dumped)



Either of these approaches work if loops = 207500 or smaller. However if I increase this (e.g. 2100000) I get the error



#include 

void main()
{

long i;
long loops;

loops = 2075000; // works
loops = 2100000; // Segmentation fault (core dumped)

if (1) {
int arr[loops]; // stack array
for (i = 0; i < loops; i++) {
arr[i] = 3;

}
}

if (1) {
int *arr = (int *) malloc(sizeof(int) * loops); // heap array
for (i = 0; i < loops; i++) {
arr[i] = 3;
}
}


}


I'm using Ubuntu 12.04 LTS via Virtual box with 8gb ram allocated

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...