7

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

shader
  • 447
  • 3
  • 13
  • Also: Use a *scanline* flood fill. It usually doesn't require that much stack space. Also: Use your own stack and make your function iterative. – sellibitze Aug 26 '10 at 07:29

3 Answers3

15

Use

gcc -Wl,--stack,N

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

denis
  • 422
  • 4
  • 10
1

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

Ilya
  • 125
  • 5
0

probably the best bet is to use pthreads to start a new thread and run your algorithm in the new thread. One of the parameters to pthread_create is pthread_attr_t. Using this attribute you can specify the stack size (by calling pthread_attr_setstacksize).

Edit: Whether this works or not is dependent on support of the underlying compatibility layer

doron
  • 27,972
  • 12
  • 65
  • 103