Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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().



Not 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.


Ignoring 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.


>setrusage()

Is it old version of setrlimit()? Couldn't locate it in any of the man.*bsd.org.


My bad, that's what I intended to say.


I did found plenty of docs and books mentioning setrusage() though, like a proper Mandela Effect.


> 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: