d future or plans for d3
deadalnix
deadalnix at gmail.com
Tue Dec 20 05:41:40 PST 2011
Le 20/12/2011 14:08, Andrei Alexandrescu a écrit :
> On 12/20/11 5:56 AM, Froglegs wrote:
>>
>>> 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.
>>
>> Ah, makes sense now, thanks.
>>
>> Still it seems like a case of "you pay for what you don't use", and
>> seems like a real downer for adopting D since you loose the ability to
>> use lambda's without having the GC shoved down your throat(wouldn't be
>> so bad if the D GC was known for performance, but everything I've read
>> indicates it is quite slow).
>
> D's pass-down lambdas do not need memory allocation. As far as I
> remember none of std.algorithm's use of lambda allocates memory.
>
> Andrei
Is the compiler able to ensure that and do not allocate on the heap ?
More information about the Digitalmars-d
mailing list