Memory allocation purity

Brian Schott via Digitalmars-d digitalmars-d at puremagic.com
Wed May 14 18:11:30 PDT 2014


On Thursday, 15 May 2014 at 00:48:52 UTC, Walter Bright wrote:
> On 5/14/2014 5:44 PM, Brian Schott wrote:
>> Can we say that Mallocator failures are not recoverable?
>
> malloc itself does not have that property. But you could design 
> a wrapper for it that did.

I'm concerned specifically with this wrapper: 
https://github.com/andralex/phobos/blob/allocator/std/allocator.d#L773

We need to make these functions pure if they are going to be 
usable.

Removing the stdlib import and adding

private extern (C)
{
     void* malloc(size_t) pure nothrow @trusted;
     void free(void*) pure nothrow @trusted;
     void* realloc(void*, size_t) pure nothrow @trusted;
}

as well as a throwing OutOfMemoryError if they fail should be 
sufficient, correct?


More information about the Digitalmars-d mailing list