C# Recursion Depth - How Deep can you go

前端 未结 4 1983
猫巷女王i
猫巷女王i 2020-11-30 06:44

Is there any control how much you can Recursively call something?

From a basic test program I get a recursion depth of just over 18k

which depends on the sta

4条回答
  •  一向
    一向 (楼主)
    2020-11-30 06:53

    I think you are risking problems here. It's hard to determine exactly how much stack a recursive algorithm will use. And, if you are to the point where there's some question about if there'll be enough, I'd look for another approach.

    Most recursive algorithms could be rewritten to not be recursive. You can then allocate as much memory as you need and even recover gracefully if there's not enough.

提交回复
热议问题