我尝试对不同数据的某些函数进行研究,并为此使用 C++(听说它很快)。在这样的代码中:
std::vector<double> results;
results.reserve(100000);
using namespace std::literals;
for (int i = 1; i <= upperRange; i++) {
auto source_Filename = "Mult" + std::to_string(i) + "txt"s;
std::string in_Path = "TestData\\" + source_Filename;
std::ifstream data_File(in_Path);
if (!data_File) {
std::cout << "Error during opening file" << std::endl;
}
std::istream_iterator<std::string> start(data_File), end;
std::vector<std::string> Multiset(start, end);
results.push_back(myFunction(Multiset, b, type));
data_File.close();
}
但是对于高于 63 的 upperRange 得到以下输出:
Process finished with exit code -1073740940 (0xC0000374)
我已经对此进行了一些研究,并发现它可能与堆损坏有关。 python 有一个类似的主题,解决方案是在控制面板中更改 UTF-8 选项(没有帮助)。我已经测试了 myFunction 并且对任何单个数据都运行良好,此外,当我尝试调试我的程序时,即使对于 upperRange = 10^4,我也没有收到任何错误。我真的很好奇这个问题的原因。如果它在我的代码中,我该如何改进以提高安全性(我知道在使用 C/C++ 时可能会出现内存错误)。
技术细节:
工具集:捆绑的 MinGW 版本:w64 9.0
CMake:捆绑版本:3.25.2
构建工具:ninja.exe
C++ 编译器:g++.exe
调试器:捆绑的 GDB 版本:12.1