【发布时间】:2017-04-07 17:14:17
【问题描述】:
我编写了一个 C++ 程序,当它被编译为 64 位可执行文件时,它在 Linux 上运行良好。我还在 Windows 上将它编译为 32 位可执行文件,它崩溃并显示以下消息:
boost\boost_1_55_0\boost/test/minimal.hpp(123): exception "std::bad_alloc: bad allocation" caught in function: 'int __cdecl main(int,char *[])'
由于我必须分配大小为 20000*20000 的整数矩阵,我告诉自己我可能超出了 32 位平台上允许的大小...
所以我将它编译为 64 位 Windows 可执行文件,它工作正常。为了检查我的假设是否正确,我决定将其编译为 32 位 Linux 可执行文件并且......它也可以正常工作吗?所以我不知道崩溃的原因可能是什么......
- 32 位 Windows => 使用标准 bad_alloc 崩溃
- 64 位 Windows => 运行正常
- 32 位 Linux => 运行正常
- 64 位 Linux => 运行正常
【问题讨论】:
-
无法重现问题。请与我们分享minimal reproducible example。注意,我们不需要完整的代码,我们需要制造的minimal reproducible example。
标签: c++ linux windows boost 32bit-64bit