Memory allocation purity
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Wed May 14 18:33:28 PDT 2014
On 5/14/14, 5:44 PM, Brian Schott wrote:
> On Thursday, 15 May 2014 at 00:00:37 UTC, Walter Bright wrote:
>> On 5/14/2014 3:42 PM, Brian Schott wrote:
>>> If malloc can never be considered pure, even when hidden behind an
>>> allocator,
>>
>> It cannot be pure as long as it can fail.
>>
>>> why can it be considered pure when hidden behind the GC?
>>
>> Because GC failures are not recoverable, so the pure allocation cannot
>> fail.
>
> Can we say that Mallocator failures are not recoverable?
FWIW std.allocator allows constructing a bunch of small-business
allocators for which failure to allocate is entirely legit. The methods
of such allocator may be weakly pure.
An allocator that ultimately falls back to GCAllocator and "never fails"
should be pure - better yet, inferred as such.
Andrei
More information about the Digitalmars-d
mailing list