4 ms·
On Linux machines malloc()'s returning NULL doesn't mean you're out of memory, it means you're out of address space which is very different.
by bestouff 5y ago
On Linux machines malloc()'s returning NULL doesn't mean you're out of memory, it means you're out of address space which is very different.
- fjfaase 5y agoIf I understand it correctly, it is even worse, because malloc could return not NULL and still throw an exception when you try to write to the 'allocated' memory. See for example https://linuxembedded.fr/2020/01/overcommit-memory-in-linux https://linuxembedded.fr/2020/01/overcommit-memory-in-linux
- omnicognate 5y agoIn a system with virtual memory there are a variety of limits you can hit that will prevent your process allocating more memory and cause malloc to return zero. It's normal to informally lump all these together as "running out of memory" when the distinction doesn't matter, as here. Address space size is one of these limits, not the only one. Hitting it is rare on 64-bit operating systems, common on 32-bit ones.
- kaba0 5y agoUnfortunately, I’ve yet to come across a major application on linux that handles this condition gracefully.