下面的代码不会抛出异常,并输出“成功”。为什么?
#include <iostream>
int main()
{
size_t size = size_t(1024)*1024*1024*1024*1024*1024*1024*1024;
char* data = new char[size];
if (data == NULL)
std::cout << "fail" << std::endl;
else
std::cout << "success" << std::endl;
return 0;
}
如果这就是它的工作方式,我如何检查我是否有足够的内存?
编辑:让我愚蠢的代码更正确了一点,现在如果我删除两个*1024
,它至少会在x64上失败
https://stackoverflow.com/questions/12507456
复制相似问题