简体   繁体   English

堆内存上的Python递归

[英]Python recursion on heap memory

Is there any good methods to place recursion stack on heap to prevent stack overflowing? 有什么好的方法可以将递归堆栈放在堆上以防止堆栈溢出?

Of course, there is method to store own stack and place there function's variables (frame) and just simulate recursion, and, by all appearances, I'm looking for something like decorator, which will do it automatically. 当然,有一种方法可以存储自己的堆栈,并在其中放置函数的变量(框架),并且仅模拟递归,而且,从所有方面来看,我正在寻找诸如decorator之类的东西,它将自动完成。

There are a few options here. 这里有一些选择。

  1. Use stackless Python, as the name would suggest it doesn't have this problem. 使用无堆栈Python,顾名思义,它没有这个问题。
  2. Build your own stack instead of using recursion 构建自己的堆栈,而不使用递归
  3. NOT RECOMMENDED Increase the recursion limit https://docs.python.org/2/library/sys.html#sys.setrecursionlimit 不建议增加递归限制https://docs.python.org/2/library/sys.html#sys.setrecursionlimit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM