Following code doesn’t throw exception and prints “success”. Why ?
#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;
}
- Compiler: g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
- OS: Ubuntu 12.04
- RAM: 8 GB
And if this is how it’s meant to work, how do I check that I have enough memory ?
[Edit: made my stupid code a bit more correct, now it would at least fail on x64 if I remove two *1024]
My compiler can answer this one: