In C++, you can arrange for a function to be called whenever new
fails. Is there a way to have a function called whenever malloc
fails? Assume that malloc
is being called from third-party libraries that I don't want to change.
I don't think there's a portable answer, so I'll happily accept platform-specific ones. I'm using Linux+uclibc on some platforms and Linux+glibc on others. I'm planning to use setrlimit
to limit the amount of memory malloc
can return.