1

Is there a pessimistic way of figuring out if a malloc will fail. I am somewhat worried about this:

By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. In case it turns out that the system is out of memory, one or more processes will be killed by the OOM killer. For more information, see the description of /proc/sys/vm/overcommit_memory and /proc/sys/vm/oom_adj in proc(5), and the Linux kernel source file Documentation/vm/overcommit-accounting.

If I were not aware of this disclaimer, I would just check if malloc succeeds.

In my case memory is a constraint since the application needs allocate a large data block (gigabytes). Gimp moves the entire responsibility to the user via its configuration dialog. I want to have something that deduces a soft upper limit.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user877329
  • 6,717
  • 8
  • 46
  • 88

0 Answers0