Memory allocation purity

Manu via Digitalmars-d digitalmars-d at puremagic.com
Thu May 15 04:52:20 PDT 2014


On 15 May 2014 10:50, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 5/14/2014 5:03 PM, Meta wrote:
>>
>> Allocating memory through new and malloc should always be pure, I think,
>> because
>> failure either returns null in malloc's case,
>
>
> malloc cannot be pure if, with the same arguments, it returns null sometimes
> and not other times.

Even if it doesn't fail, malloc called with identical arguments still
returns a different result every time.
You can't factor malloc outside a loop and cache the result because
it's being called repeatedly with the same argument like you're
supposed to be able to do with any other pure function.
You shouldn't be able to do that with gcalloc either... how can gcalloc be pure?


More information about the Digitalmars-d mailing list