Created
January 18, 2012 19:56
-
-
Save justinsb/1635174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir test | |
cd test | |
cat > test.cc <<EOF | |
#include <memory> | |
#include <iostream> | |
using namespace std; | |
static const size_t kMaxSize = ~static_cast<size_t>(0); | |
static const size_t kNotTooBig = 100000; | |
// We want an allocation that is definitely more than main memory. OS | |
// X has special logic to discard very big allocs before even passing | |
// the request along to the user-defined memory allocator; we're not | |
// interested in testing their logic, so we have to make sure we're | |
// not *too* big. | |
static const size_t kTooBig = kMaxSize - 100000; | |
int main() { | |
try { | |
char * p = new char[kTooBig]; | |
cout << "Allocation OK\n"; | |
} | |
catch (std::bad_alloc& a) { | |
cout << "Allocation threw bad alloc\n"; | |
} | |
return 0; | |
} | |
EOF | |
g++ -m32 test.cc; ./a.out | |
# Allocation threw bad alloc | |
g++ -m64 test.cc; ./a.out | |
# Segmentation Fault (core dumped) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment