On 5/16/15 2:07 AM, Walter Bright wrote:
On 5/15/2015 6:38 PM, Andrei Alexandrescu wrote:
Yeh, failed allocations are relatively frequent within the framework
components.

I find this surprising.

Consider a fixed-length buffer fronting a general allocator, one of the simplest and most useful compositions of allocators, which I call FallbackAllocator:

https://github.com/andralex/phobos/blob/allocator/std/experimental/allocator/fallback_allocator.d

Once the memory in the front buffer is exhausted, the fallback allocator starts getting used. The correct way to handle the choice in the composer is to first try the front, and if it returns null, defer to the fallback.

Many other allocators follow similar patterns.


Andrei

Reply via email to