4 ms·
~ $ cat a.cpp #include <vector> int main() { std::vector<int> v; v.reserve(1ULL<<32); } ~ $ g++ a.cpp ~ $ sudo sh -c 'echo 0 > /proc/sys/v
by edflsafoiewq 5y ago
~ $ cat a.cpp
#include <vector>
int main() {
std::vector<int> v;
v.reserve(1ULL<<32);
}
~ $ g++ a.cpp
~ $ sudo sh -c 'echo 0 > /proc/sys/vm/overcommit_memory'
~ $ ./a.out
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)
~ $ sudo sh -c 'echo 1 > /proc/sys/vm/overcommit_memory'
~ $ ./a.out
~ $
- jeffbee 5y agoI see, thanks. It didn't seem to matter on my box, but perhaps that's what "heuristic overcommit" means: outcomes may vary?