Linux optimistic malloc: will new always throw when out of memory?

后端 未结 5 1656
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 05:04

I have been reading about out of memory conditions on Linux, and the following paragraph from the man pages got me thinking:

By default, Linux follows

5条回答
  •  庸人自扰
    2020-12-03 05:29

    You can't handle it in your software, pure and simple.

    For your application you will receive a perfectly valid pointer. Once you will try to access it, it will generate a page fault in the kernel, the kernel will try to allocate a physical page for it and if it can't ... boom.

    But as you see, all this happens inside the kernel, your application cannot see that. If it's a critical system you can disable the overcommit alltogether on the system.

提交回复
热议问题