how to set stack size with GCC MinGW

Jun 3, 2014 at 4:00pm
Hi all. I'm following a course with coursera (algorithm 1) and my program for the assignment crashes inexorably (many are experimenting the same thing there, the assignment asks for a recursive program for solving a big graph of 500000 nodes). I'm using a version of g++ from MinGW with the editor Geany and windows7. The current setup is:

g++ -std=c++11 -Wall -c "%f"

g++ -std=c++11 -Wall -o "%e" "%f"

How can I set the stack 'unlimited'?
Jun 3, 2014 at 4:22pm
Well, I don't know if you can set it to unlimited, but (assuming Windows) you can try passing
-Wl,--stack,<size>
(where <size> is in bytes)
to set the stack size.

(From doing some tests, it seems the default is 2 MB)
Jun 3, 2014 at 5:18pm
Having a program crash is about as generic as an error can get. What makes you suspect that the stack size is the issue? Do you get a run time error code? What does event viewer tell you about the crash?
Jun 3, 2014 at 9:01pm
There technically are ways of making an arbitrarily large stack, if you're willing to mess around with Assembly. It's a really ugly solution, though, and I don't recommend it ever.

IMO, if you have to process an arbitrarily large data structure recursively, you should put the recursion somewhere that isn't the call stack. Hell, even making a dynamically allocated pseudo-stack+switch is better.
Jun 4, 2014 at 7:21am
Thank you all. I guess Computergeek01 is right. The fact is I'm not able (for now) to make my implementation of Kosaraju's algorithm work. I have read on the forum of coursera that some have solved their problems by enlarging the stack on their computers, so I was trying this way "blindly", so to say, but I have changed my mind now; after all I'm there to learn. It's a really hard assignment - compared to my current skills. For some days now I have been trying to write a iterative version of that algorithm, I hope to succeed. Thank you all again.
Last edited on Jun 4, 2014 at 7:21am
Jun 6, 2014 at 10:48am
well, just a little update for those who may need the same piece of information in the future. I succeeded in doing the program work; it was correct and simply needed more memory, as many suggested in the coursera forum, because the graph had 500000 nodes and 5 million edges. In windows7 the default stack size is 1MB. As "long double main" wrote, the command is
-Wl,--stack,<size>
In the GCC Options for Linking (http://gcc.gnu.org/onlinedocs/gcc-3.0/gcc_3.html#SEC16) I read that
-Wl\,option Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas.
In the Geany editor I found by trials that the instruction may be:
g++ -std=c++11 -Wall -Wl,--stack -Wl,<size> -o "%e" "%f"

I set <size> to a very large number, just to solve my problem; then I set again the default:
g++ -std=c++11 -Wall -o "%e" "%f"
Last edited on Jun 6, 2014 at 10:55am
Topic archived. No new replies allowed.