Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple multi-dimensional C-style array gives segmentation fault : 11

Tags:

c++

const int L=10;
std::complex<double> c_array[L][L][L][L][L][L]    // 6 dimensions

Space needed: 2*8*10^6 bytes

It should not use up all of memory, right?

like image 899
Tim Avatar asked Jul 08 '13 04:07

Tim


1 Answers

There is a stack size limit for every processes. Therefore, if you really want to create this array locally (in the stack), the only solution is to increase the stack size limit for your program. How to change the stack size limit depends on your OS.

Alternative is to create this array in the heap. To do that you have to use "new" keyword as follows.

std::complex<double> *c_array = new std::complex<double>[L][L][L][L][L][L]; 
like image 139
SRF Avatar answered Oct 30 '22 04:10

SRF