4 ms·
Whether this works depends on several things, like /proc/sys/vm/overcommit_memory and how much RAM+swap you actually have available.
by edflsafoiewq 5y ago
Whether this works depends on several things, like /proc/sys/vm/overcommit_memory and how much RAM+swap you actually have available.
- jeffbee 5y agoNo, this is the behavior for any value of vm.overcommit_memory.
- 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?