News for hackers. Stuff that matters.
Re:Practical Guide to Bare Metal C++ by smelterdemon on Friday June 02, 2017 @02:57PM (#14472451)
Can you give an example of how one could recover from a bad alloc (especially in a "bare metal" situation where you probably can't move anything to disk)?
Re:Practical Guide to Bare Metal C++ by maccard on Friday June 02, 2017 @03:45PM (#14472790)
It's contrived, but; imagine a mark and sweep garbage collector. Instead of freeing memory, you mark it as free-able. When you get a bad alloc you an then sweep and actually free the resources, and retry the allocation.

A more realistic example might be if you have an application that allocates a large chunk of memory up front for processing later. If it fails, you can stall until a point where you know the memory will be available, or you could retry with a smaller allocation.