Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase stack size when compiling with mingw?

I'm writing a recursive flood-fill algorithm to find connected components in an image, my code compiles and runs well with MSVC 2008 compiler; but the mingw-compiled binary crashed at runtime.

After I converted the algorithm to non-recursive with std::stack, everything goes well.

But what if I must use recursive algorithm in some case, and mingw cannot handle it?

How can I increased stack size of a binary, is there any compilation options?

Thanks

like image 820
shader Avatar asked Aug 24 '10 14:08

shader


2 Answers

Use

gcc -Wl,--stack,N

where N is stack size. E.g. gcc -Wl,--stack,4194304

like image 166
denis Avatar answered Nov 15 '22 03:11

denis


Maybe increasing stack size is not the solution you want. These restrictions do exist for a reason. It also may happen that in a near future your algorithm will use even more stack space and you will have to increase it again.

Perhaps you should consider converting your algorithm into a non-recursive one. This can be done for every algorithm. See this discussion

And you will probably gain a performance improvement also

like image 30
Ilya Avatar answered Nov 15 '22 02:11

Ilya