U_int64_t array
I am trying to do this:
int main(void){
u_int64_t NNUM = 2<<19;
u_int64_t list[NNUM], i;
for(i = 0; i < 4; i++){
list[i] = 999;
}
}
Why am I getting a segfault on my 64 bit Ubuntu 10.10 (gcc 4.6.1)?
You are trying to create a very large array on the stack. This leads to a stack overflow.
Try allocating the array on the heap instead. For example:
// Allocate memory
u_int64_t *list = malloc(NNUM * sizeof(u_int64_t));
// work with `list`
// ...
// Free memory again
free(list);
You announce NNUM = 2*2^19 == 2<<19 == 1048576
.
and try to stack 64 bits * 1048576 = number of bits * multiple cells. This is 8.5 MegaBytes
, this is too much to allocate on the stack, you can try to allocate it on the heap and check if it actually works using the return value malloc
.
a bunch of VS. stack
Your program requires a minimum stack size of 1048576, if you specify "ulimit -s" it is most likely less than that. you can try "ulimit -s 16384" and then redo again.