maximum possible recursion

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I want to know if we have any limit for calling any function recoursively.
If there is any, On what parameters this limit depends? and is it different
for .net 1.0, 1.1 and 2.0?
Thank you,
-yogee
 
I want to know if we have any limit for calling any function recoursively.

Yes we have.
If there is any, On what parameters this limit depends?

It depends on size and number of parameters, local variables,return types
and which expressions are used in the methods, and which kind of processor
you have (32 or 64 bit)
and is it different for .net 1.0, 1.1 and 2.0?

Yes is also dependent of the implementation of the framework.

There is no definite way to tell how much stack is free and how deep you can
recurse.
You can set the stacksize limit for each thread if you know that the size
isn't enough.
The best way would be trying to solve the problem without recursion, that is
most times possible.
 
Hi Yogee,

As the other repliers have stated, it depends on the thread's stack size. As
far as I know, and value types are pushed directly onto the stack along with
the call. Reference types are only passed as pointers to the object.
Therefore, it would depend on the stack memory requirements for the
parameters as well as the actual stack space allocated. I would suggest using
reference types, module-level variables or statically declared variables if
you can. Also, you may be able to reduce the actual storage requirements for
things like strings if you place them within an array instead of in
individual parameters as I believe that .net allocates pointers to arrays
rather than potentially attempting to store the actual string data within the
stack itself.

Hope this helps.

-Eric
 
Eric Giles said:
As the other repliers have stated, it depends on the thread's stack size. As
far as I know, and value types are pushed directly onto the stack along with
the call. Reference types are only passed as pointers to the object.
Therefore, it would depend on the stack memory requirements for the
parameters as well as the actual stack space allocated. I would suggest using
reference types, module-level variables or statically declared variables if
you can.

Or trying to reduce the level of recursion...
Also, you may be able to reduce the actual storage requirements for
things like strings if you place them within an array instead of in
individual parameters as I believe that .net allocates pointers to arrays
rather than potentially attempting to store the actual string data within the
stack itself.

Strings are already reference types. The sequence of characters in a
string is never present on the stack.
 
So the recursuion depth is limited by the thread's stack size ! What
exception do I need to catch if stake is full ?
And what if I create my own stakes to store parameters and other variables..
i.e. simulate process of recursion ? Is it better option than inbuilt one?
 
Back
Top