pythonic metaphor
pythonic metaphor

Reputation: 10556

Operator new and bad_alloc on linux

On Linux, malloc doesn't necessarily return a null pointer if you're out of memory. You might get back a pointer and then have the OOM killer start eating processes if you're really out of memory. Is the same true for c++'s operator new or will you get the bad_alloc exception?

Upvotes: 3

Views: 1255

Answers (2)

caf
caf

Reputation: 239171

It's a kernel function rather than a language function - and you can control it with the vm.overcommit_memory and vm.overcommit_ratio sysctls.

They're visible in the proc filesystem at /proc/sys/vm/overcommit_memory and /proc/sys/vm/overcommit_ratio.

Upvotes: 7

Jeremy Friesner
Jeremy Friesner

Reputation: 73161

The same is true for operator new, alas :^(

Upvotes: 4

Related Questions