Operator new and bad_alloc on linux

笑着哭i 提交于 2019-12-10 20:12:36

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/1592535/operator-new-and-bad-alloc-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!