std.allocator.allocate(0) -> return null or std.allocator.allocate(1)?

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sat May 16 13:22:35 PDT 2015


On 5/16/2015 9:34 AM, Andrei Alexandrescu wrote:
> 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.

Ah, ok, that makes sense. I was thinking more in terms of the whole program 
running out of memory, not fallback.



More information about the Digitalmars-d mailing list