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?
Asked
Active
Viewed 1,933 times
2
-
3Are you sure you want to go deeper? That's a lot of recursion, I think. You might try making it iterative. – GManNickG Oct 11 '09 at 05:27
-
I am doing memoization for DP. Its a problem on 3 by 3 matrix , converting one config to other config. I cant make it iterative. – avd Oct 11 '09 at 05:31
-
1@aditya: all recursive algorithms *can* be made iterative; it is often hard to do so and you may not know how to do it. – Jonathan Leffler Oct 11 '09 at 05:51
2 Answers
9
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
- 124,830
- 17
- 198
- 235
4
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.
-
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 Oct 11 '09 at 05:32