开发者

Increase stack size when compiling with mingw?

I'm writing a recursive flood-fill algorithm to find connected components in an image, my code compi开发者_高级运维les 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


Use

gcc -Wl,--stack,N

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜