开发者

Operator new and bad_alloc on linux

开发者 https://www.devze.com 2022-12-09 12:21 出处:网络
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 ki开发者_开发问答ller start eating processes if you\'re really o

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 ki开发者_开发问答ller 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消