您好,我正在运行一个递归代码,我意识到在我的个人计算机上,运行默认的Visual Studio调试器时,在使用无调试运行选项时,我只能容纳6776次,直到出现堆栈溢出错误。使用调试器时,我可以将其获取到6781。在cpp.sh上,我可以获取到9亿。我怀疑是缓存,但是它仍然不能解释所有问题。因为它比onlinegdb准确得多(只有205000),所以我的计算机的能力明显比cpp.sh使用的服务器低,但不比132,723倍低。正在使用什么软件和硬件欺骗手段,以及如何使其一致?
注意:我不是在问最大数量,我只是在问其他因素和增加数量的方法。如果有人使用不同的软件和硬件配置来测试代码,那就太好了。
注2:在运行SDM660 / 4GB / 9.0 9月更新的手机上,我得到360,000。注意3:因为我不想让它死掉,所以我做了更多的搜索。此现象仅在完整的优化设置中有效。中等和无仅会给出细分错误。由于某种原因,Maximum仅返回一个整数,然后迅速返回。仍然,它切到哪个角落?
我正在使用具有4GB Ram的Intel N3350运行Windows 10版本1903。
int main() { long double Answer = 0; Answer = 3 + (Solver(2, 1, UserInput, 0)); } double Solver(int counter, int group, int stop, long double partialanswer) { long double Counter = counter; if (Counter >= stop) { return partialanswer; } if (group % 2 != 0) { partialanswer = partialanswer + (4 / ((Counter) * (Counter + 1) * (Counter + 2))); } else { partialanswer = partialanswer - (4 / ((Counter) * (Counter + 1) * (Counter + 2))); } Solver((counter + 2), (group+1), stop, partialanswer); }
注3:如果需要,请提供完整的代码。
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double Solver(int counter, int group, int stop, long double partialanswer)
{
long double Counter = counter;
if (Counter >= stop)
{
return partialanswer;
}
//partialanswer = round(partialanswer * pow(2, 54)) / pow(2, 54);
if (group % 2 != 0)
{
partialanswer = partialanswer + (4 / ((Counter) * (Counter + 1) * (Counter + 2)));
}
else
{
partialanswer = partialanswer - (4 / ((Counter) * (Counter + 1) * (Counter + 2)));
}
Solver((counter + 2), (group+1), stop, partialanswer);
}
int main()
{
int UserInput;
long double Answer = 0;
cin >> UserInput;
Answer = 3 + (Solver(2, 1, UserInput, 0));
cout << "PI = " << setprecision(18) << Answer << endl;
cout << "reference Pi is equal to 3.1415926535897932384626433832795028841971 " << endl;
cout << " The Difference is equal to " <<fixed << setprecision(30) << abs(Answer - 3.1415926535897932384626433832795028841971) << endl;
}
嗨,我正在运行一个递归代码,我意识到在我的个人计算机上,运行默认的Visual Studio调试器时,使用不带调试选项的运行时,我只能容纳6776次...]]
在Windows中是典型的thread stack size 1Mb(在工具链之间可能有所不同-GCC,VC ++等,但数量级不同)。要更改堆栈大小,请查阅工具链的文档。
每个调用将占用一个堆栈帧,其大小将取决于其局部变量和参数的大小,再加上返回地址的大小并考虑数据对齐填充。