<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr">Am Fr., 16. Nov. 2018, 03:25 hat Ryan Joseph <<a href="mailto:ryan@thealchemistguild.com">ryan@thealchemistguild.com</a>> geschrieben:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Nov 15, 2018, at 11:30 PM, Sven Barth via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>> wrote:<br>
> <br>
> No, too many ways to do the same thing don't make things easier, not to mention that everything needs to be maintained. So this gets a definite "no" from me. <br>
> <br>
> Also the overhead for calling an anonymous function is only that for a virtual method call. <br>
<br>
Do you mean if the anonymous function has no state it’s only a single function call?<br>
<br>
After reading old forum posts it sounded like this was going to be implemented by some reference counted structure which was allocated on the heap and even using interfaces perhaps. Depending on how this is implemented it may not be possible to prevent them from capturing state if the anonymous function accesses variables in the parent scope.<br>
<br>
How much of that is accurate?<br></blockquote></div><div dir="auto"><br></div><div dir="auto">When a function contains at least one anonymous function then a capture object is created which is shared by all anonymous functions in the function and also all captured local variables are moved there. If there is no variable to capture the capture object is nevertheless created. </div><div dir="auto">The call of an anonymous function is then always a virtual method call trough the interface VMT of the anonymous function into the capture object. </div><div dir="auto">So if you call an anonymous function multiple times you only have the overhead of the virtual method call, but only once the impact for creating the capture object (which might happen in different locations anyway if you pass an anonymous function outside of its declared scope). </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div>