I want to know what is the maximum number of (recursive)function calls allowed in gcc C. I have a program which can take stack depth of 400000 function calls each with size of around 200 bytes (so around 80 MB). How can I increase the maximum depth?
+2
A:
I would recommend rewriting the routine into an iterative algorithm. Though nontrivial it should be straightforward to convert the algorithm, and will free you from having to deal with such resource limitations (which, I would guess, vary wildly by architecture, platform, computer details, etc.)
Also, please note: all recursive algorithms can be written iteratively.
fbrereto
2009-10-11 05:31:07
I am doing memoization for DP. Its a problem on 3 by 3 matrix , converting one config to other config. Making iterative is difficult.
avd
2009-10-11 05:32:35
+5
A:
The stack limit is not imposed by the compiler, but by the operating system. On Unix, you can try using ulimit(1) to increase it.
Martin v. Löwis
2009-10-11 05:35:01