使用 GNU CLIsp 获取堆栈溢出 (Windows)
我在运行程序时收到“程序堆栈溢出重置”消息。因此,我设置添加了一个计数器来查看我在程序中递归调用主函数的次数。事实证明,它大约是 30,000 次,而且我正在堆叠的数据是长度约为 10 个元素的列表,我认为数量并不多。我的问题是这种数量的递归调用和内存使用是否常见,或者更有可能是我做错了什么?我检查了vista的资源管理器,发现lisp.exe进程的内存仅增长了1MB左右。如何调整CLisp的堆栈溢出限制?
I'm getting "Program stack overflow RESET" message while running my program. So I set added a counter to see how many times I'm recursively calling the main function in my program. Turns out that it is around 30,000 times and the data I'm stacking are lists of length around 10 elements, which I think are not so many. My question is whether this amount of recursive call and memory usage are common or not, or is it more likely that I'm doing something wrong? I checked the resource manager of vista and found the memory only grew for like 1MB for lisp.exe process. And how do I adjust the stack overflow limit of CLisp?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://clisp.cons.org/impnotes.html#faq-stack
请注意,如果您进行尾部调用并编译您的函数,则根本没有限制。
http://clisp.cons.org/impnotes.html#faq-stack
Note that if you do tail calls and compile your function(s) there will be no limit at all.
1 MB 似乎是 Windows 上的默认堆栈大小。我不知道是否可以在不重新链接程序的情况下更改它,但无论如何,我建议将程序转换为尾递归形式并使用 CLIsp 字节编译器,这将优化它,或者只是将其转换为迭代形式。虽然许多 Common Lisp 编译器确实实现了尾调用优化,但标准并不要求它,因此不应使用无界递归。
1 MB seems to be the default stack size on Windows. I do not know if it is possible to change it without relinking the program, but in any case I would recommend either converting the program to tail-recursive form and using the CLisp byte compiler, which will optimize it away, or just converting it to iterative form. While many Common Lisp compilers do implement tail call optimization, the standard does not require it, so unbounded recursion should not be used.