Hacker News new | ask | show | jobs
by ncmncm 2315 days ago
When the global allocator fails, you might not be able to do much... except set a flag, and free a big block of memory that was reserved against just such an event.

Then the program can do whatever cleanup is warranted, maybe freeing up a variety of other resources, and then maybe re-reserve that block, and forge ahead.

But when you actually care about performance, you often are not using the global allocator. A local allocation failure is nothing to panic over. Generally, only the higher level code -- where the handler is -- knows, or needs to care, what kind of allocator failed. The low-level code gets to just bail out, as it should.

1 comments

You could also have just tried to allocate 42 terabytes of memory and have a well defined strategy for what to do in case this fails...
Yeah, but in that case you would use your own allocator fit for this purpose and not just new or malloc.