d future or plans for d3

Vladimir Panteleev vladimir at thecybershadow.net
Tue Dec 20 03:39:29 PST 2011


On Tuesday, 20 December 2011 at 11:17:32 UTC, Froglegs wrote:
> The array concatenation requiring GC I get, but why does a 
> delegate require it?
>
> This link says D allocates closures on the heap
>
> http://en.wikipedia.org/wiki/Anonymous_function#D
>
> I don't really get why, C++ lambda works well(aside from broken 
> lack of template lambda's) and do not require heap usage, even 
> binding it to std::function can generally avoid it if it 
> doesn't exceed the  SBO size

C++ "closures" do not allow you to maintain a reference to the 
context after the function containing said context returns. 
Instead, C++ allows you to choose between copying the variables 
into the lambda instance, or referencing them (the references may 
not "escape"). The compiler may or may not enforce correct uses 
of reference captures. In contrast, D's approach is both 
intuitive (does not copy variables) and safe (conservatively 
allocates on the heap), with the downside of requiring the 
context to be garbage-collected.


More information about the Digitalmars-d mailing list