GC.malloc is pure - wat

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 24 13:42:32 PDT 2015


On Friday, 24 April 2015 at 19:41:21 UTC, Steven Schveighoffer 
wrote:
> On 4/24/15 3:12 PM, deadalnix wrote:
>> On Friday, 24 April 2015 at 18:48:43 UTC, Steven Schveighoffer 
>> wrote:
>>> I think you are thinking of @safe-ty. malloc and free can be 
>>> pure, but
>>> must be contained properly.
>>>
>>> purity when it comes to mutable data is a tricky thing.
>>
>> No, it should not be pure because it alter global state in a 
>> manner
>> visible to the program.
>
> But so does GC.malloc.
>

No, that's the whole point of using a GC. You ask it for a chunk 
of memory, it gives you a chunk of memory. This does not affect 
any other part of your program as it is a NEW chunk of memory, so 
you are not messing with your program state.

When you free, you potentially alter references anywhere outside 
your "pure" function. It must not be pure.

Obviously, there is state involved inside the GC, but the whole 
point is that it is isolated from the program (granted the GC is 
not buggy).


More information about the Digitalmars-d mailing list