本文介绍了Fibonacci的递归调用导致堆栈溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何正确设置Java堆栈?

How exactly is the Java stack set up?

对于大学,我将确定递归计算出的最大斐波那契数方法,并且可以由堆栈处理.

For university, I shall determine what the biggest possible Fibonacci number that is calculated by a recursive method and can be handled by the stack.

有趣的是:测试表明 JVM 具有.我能够运行到Fib(4438).但是结果并不一致.有时下降到4436.

The interesting thing is: Tests showed that it doesn't matter how much -Xmx and -Xms the JVM has. I am able to run up to Fib(4438). But the results aren't consistent. Somtimes it goes down to 4436.

堆栈有公式吗?

通过 -Xss 4096m 进行的堆栈增加不会产生任何影响.

Any increase of the stack via -Xss 4096m doesn't make a difference.

推荐答案

-Xmx和-Xms设置JVM 可访问的内存,您需要增加 stack 的大小,您可以在-Xss选项的帮助下完成此操作.

-Xmx and -Xms sets memory accessible for JVM heap, you need to increase stack size, you do this with the help of -Xss option.

这篇关于Fibonacci的递归调用导致堆栈溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:51