GC.malloc is pure - wat

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 24 14:07:57 PDT 2015


On Friday, 24 April 2015 at 20:55:02 UTC, Steven Schveighoffer 
wrote:
> But I can check memory usage size and see global state has been 
> altered.
>

OK, if you want to play that game, don't access memory ever, that 
is global state. I mean, even if the memory is read only you may 
end up affecting the MMU, so that is definitively a no go. Also, 
you'd better have only a one instruction loop in your program as 
otherwise you'll affect the program counter, a definitively 
visible state from the user.

>> When you free, you potentially alter references anywhere 
>> outside your
>> "pure" function. It must not be pure.
>
> When you do ANYTHING to mutable data, you potentially alter 
> references outside your pure function. This is not a 
> disqualifier. It's accessing global sate directly that wasn't 
> passed to you that is a disqualifier.
>
> -Steve

pure function can access global immutable state that wasn't 
passed to it, so you may want to revise your definition.


More information about the Digitalmars-d mailing list