3 ms·
Where are you using this? Embedded? By default Linux is set to over commit memory, so malloc always be succeeds even if you're out of memory.
by bryanlarsen 9y ago
Where are you using this? Embedded? By default Linux is set to over commit memory, so malloc always be succeeds even if you're out of memory.
- jjnoakes 9y agoNot if process limits are set.
- SeanDav 9y ago> " By default Linux is set to over commit memory, so malloc always be succeeds even if you're out of memory." How does Linux handle 1 trillion mallocs of 1MB, on a 8GB system with 500GB hard drive, without failing? There is nothing magic about Linux, it still cannot allocate and use memory which physically and virtually is simply not there.
- steveklabnik 9y agoWhen overcommit is set, it's not malloc that fails; the OS kills your process. So, checking the result of your allocations will never let you handle this kind of error.
- rcxdude 9y agoThough if the allocation is ludicrously oversized (not sure the threshold, but 2x present memory will do it) it will just straight up fail without over-committing.
- dmpk2k 9y agoThere are other *nix OSes out there (that don't make the mistake of overcommit by default).