pnkjtr
BAN USER- 0of 0 votes
AnswersHow can we avoid a stack overflow ?
- pnkjtr in India
The problem is like this. Lets say I have a method A() invoked from main(). Now A() invokes B(), B() inturn invokes C() ... keep going...
so the current process stack will have limited capacity to accomodate all the activation frames that are being created dynamically when each new method is invoked.
so if this continues, at one point of time, stack will exhaust. so whats the method to handle this.
The very simple example can be:
void main (){
main();
return 0;
}
if you run this, we can see the error as run time error for stack overflow. in such scenario whats the optimal way to deal with it?| Report Duplicate | Flag | PURGE
Developer Program Engineer C
Hi,
My query was to know a optimal programing technique to deal with the problem as described below.
like i have a program where, there is a multilevel of invocation of methods within from prev method.
like: I invoked method A(), which in turn calls method B() within from itself. Now B() will get executed and its activation frame will occupy space in stack. before B() gets completed , it calls C(), later C() calls another D().... etc etc....
so if this continues , at one point of time, we will exhaust the allocated stack space for our program(process).
if such situation arises, whats the best programming technique to deal with this ?
I am not talking about increasing the stack size.
Hi,
My query was to know a optimal programing technique to deal with the problem as described below.
like i have a program where, there is a multilevel of invocation of methods within from prev method.
like: I invoked method A(), which in turn calls method B() within from itself. Now B() will get executed and its activation frame will occupy space in stack. before B() gets completed , it calls C(), later C() calls another D().... etc etc....
so if this continues , at one point of time, we will exhaust the allocated stack space for our program(process).
if such situation arises, whats the best programming technique to deal with this ?
I am not talking about increasing the stack size.
This will solve the issue temporarily.
- pnkjtr March 21, 2012I need a programming technique i.e we write our program in such a way that it deals with above described problem optimally.
increasing stack size is helpful, but to what limit can we increase? second thing is, we may come across above situations every time, so increasing stack may not be required.
so I need a dynamic way to deal with it..