D as a Better C

Steven Schveighoffer via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Wed Aug 23 10:43:27 PDT 2017


On 8/23/17 11:59 AM, Walter Bright wrote:
> On 8/23/2017 7:37 AM, Steven Schveighoffer wrote:
>> How do dynamic closures work without the GC?
> 
> They don't allocate the closure on the GC heap. (Or do I have 
> static/dynamic closures backwards?)

I thought "closure" means allocating the stack onto the heap so you can 
return the delegate with its context intact.

 From https://en.wikipedia.org/wiki/Closure_(computer_programming) :

"A language implementation cannot easily support full closures if its 
run-time memory model allocates all automatic variables on a linear 
stack. In such languages, a function's automatic local variables are 
deallocated when the function returns. However, a closure requires that 
the free variables it references survive the enclosing function's 
execution. Therefore, those variables must be allocated so that they 
persist until no longer needed, typically via heap allocation, rather 
than on the stack, and their lifetime must be managed so they survive 
until all closures referencing them have are no longer in use."

-Steve


More information about the Digitalmars-d-announce mailing list