3 ms·
It's a myth with unmanaged code can run out of memory to the last byte. The probability of hitting the limit is proportional to the allocation size, so the pro
by pornel 5y ago
It's a myth with unmanaged code can run out of memory to the last byte.
The probability of hitting the limit is proportional to the allocation size, so the program is most likely to hit it early on something big and easy to back out of (a buffer for a whole file, or an image bitmap) rather than literally have 0 bytes left.
Additionally, allocators typically have per-size memory pools and free lists, so even when one small allocation fails, there's still a chance that other size classes will be available.
In something like C error manual handling and freeing is hard, so the error code paths in unexpected places are likely to be untested and buggy. But with something like Rust the compiler writes cleanup code for you, so it can clean up precisely every time (if only Rust's libstd wasn't committing a suicide on OOM :()