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

1
  • 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, 2010 at 7:29

3 Answers 3

15

Use

gcc -Wl,--stack,N

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

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

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.