GC for pure functions -- implementation ideas
Don
nospam at nospam.com
Fri Apr 15 21:35:36 PDT 2011
Tomek Sowiński wrote:
> Don napisał:
>
>> LEAKY FUNCTIONS
>>
>> Define a 'leaky' pure function as a pure function which can return
>> heap-allocated memory to the caller, ie, where the return value or a
>> parameter passed by reference has at least one pointer or reference
>> type. This can be determined simply by inspecting the signature. (Note
>> that the function does not need to be immutably pure).
>>
>> The interesting thing is that heap allocation inside non-leaky pure
>> functions behaves like stack allocation. When you return from that
>> function, *all* those variables are unreachable, and can be discarded en
>> masse. Here's an idea of how to exploit this.
>>
>> THE PURE HEAP
>>
>> [snip]
>
> I'm far from being a GC expert but I think Java having identified such cases with escape analysis just puts locally allocated objects on the stack.
That works for the non-leaky function itself, but it doesn't help for
the functions it calls.
> Couldn't we too? Your mark & release "pure heap" scheme looks alright but this seems simpler.
>
> The notion of "non-leaky" functions can be useful either way.
>
More information about the Digitalmars-d
mailing list