Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stackoverflow arrays of arrays

I'm computing some values and stocking them in a variable using a function like what is below:

array<array<double,1000>,1000> index;
sum(double A, ..., array<array<double, 1000>,1000> & index);

I make a quick watch on the index array of array and it's filled with values just in the execution of the above declaration. It's OK

But! As soon as I call another function in which I use the index array, whose declaration is as follow:

average(..., array<array<double,1000>,1000> index, ...) 

I'm getting an Unhandled exception (Stack Overflow) which redirects me to an asm file (chkstk.asm):

 test    dword ptr [eax],eax     ; probe page.

Any idea how to resolve this?

like image 999
MelMed Avatar asked Mar 23 '23 12:03

MelMed


1 Answers

By default each thread in Win32 has 1 MB of stack space, and a million doubles would take up 8 MB of stack space. The solution is to allocate them from the heap using new.

like image 118
Jonathan Potter Avatar answered Apr 01 '23 23:04

Jonathan Potter