@Sunstorm said:
To be fair, I have no idea how would one go about notifying the user about being out of memory. Maybe the program could tear itself down to try freeing memory, and then try notifying? I can't really imagine most programs going through the effort.
Windows at least has a solution for this one... if you bring up a message box with the "Error icon" and "System Modal" flags set, it'll always succeed even if there's no memory available - all the memory needed for the message box is pre-allocated when windows starts, and a lot of the processing that Windows normally does on message boxes is disabled (no word wrap, message must be at most 3 lines long).
So I've got this code in most of my programs:
void * malloc_or_die (size_t n)
{
void *ptr = malloc(n);
if (!ptr)
{
MessageBox(NULL, "Out of memory.", "Error", MB_ICONHAND | MB_SYSTEMMODAL);
exit(1);
}
return ptr;
}
It wouldn't surprise me if the Mac had something similar.