Can we fix this?

deadalnix deadalnix at gmail.com
Thu Sep 30 19:38:15 UTC 2021


On Thursday, 30 September 2021 at 14:42:34 UTC, Steven 
Schveighoffer wrote:
> Consider:
>
> ```d
> void delegate() dg;
> for(int i = 0; i < 100; ++i)
> {
>    dg = { writeln(i); };
> }
>
> dg();
> ```
>
> What `i` is printed? Note that there is only one `i` variable 
> over the entire loop.
>
> -Steve

It's a good example of things that the optimizer shoudl handle. 
In that specific case, you shouldn't expect any memory allocation 
because the delegate never escape.


More information about the Digitalmars-d mailing list