3 ms·
> Many programmers, including myself, have gotten out of the habit of doing this on modern systems like Linux, because a malloc() call always succeeds, regardle
by jart 2y ago
> Many programmers, including myself, have gotten out of the habit of doing this on modern systems like Linux, because a malloc() call always succeeds, regardless how much memory is available.
Not if you use setrusage().
- fuhsnn 2y ago>setrusage() Is it old version of setrlimit()? Couldn't locate it in any of the man.*bsd.org.
- jmclnx 2y agoNot me :) What I develop I always make sure I test on NetBSD and OpenBSD. That keeps me honest and those systems will find issues that Linux does not care about. I found many issues by testing on those systems. Also, ignoring malloc() returns is dangerous if you want to port your application to a UNIX like AIX.
- antirez 2y agoIgnoring failures is a bad idea, but in many applications quitting on malloc() retiring NULL is the most sensibile thing to do. Many, but not all kinds of applications.
- guenthert 2y ago> Not if you use setrusage(). Or if memory overcommit is disabled or an 'unreasonable' amount of memory was requested. So, no, malloc() doesn't always succeed.