c# - A calls B where B calls A, huge stack trace -
i have class has 2 methods this:
int counter = 0; private void () { debug.log (system.environment.stacktrace); counter++; b (); } private void b () { counter++; if (counter < 100) (); }
this compiles , works fine , stops after 100 iterations expected. however, i'm bit worried end of it, stack trace gets rather enormous.
i tried searching kind of pattern, couldn't find anything. doing in general no-no, or fine, long terminates properly?
edit: clarification on use of this: main loop of program should keep going forever; it's not meant kind of recursive function. have 1 big loop, split multiple smaller methods various reasons , call each other in fashion. functionally it's same having code in giant while loop, i'm worried stack trace.
this recursive pattern, , not per se bad design. long stack generated recursive calls (depend on number of calls, , number of arguments per calls) not exceed maximum stack size (by default 1 mb .net applications), fine.
if exceed it, have write (necessarily existing) imperative equivalent.
note:
100 functions calls nothing compared stack size.
Comments
Post a Comment