<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Mi., 16. Feb. 2022, 03:14:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Feb 15, 2022, at 11:09 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>
> For a global function the compiler has to generate a wrapper that gets rid of the Self parameter of the interface. <br>
> <br>
<br>
The compiler generates this interface at compile time right? And then when the scope of the calling function is entered the interface is allocated? I know that's how it works for the case when state is captured but I think you're saying this is happening any time a function reference is assigned to, even if there is no state captured. Just trying to get an understanding of the runtime cost to use these.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">The compiler is generating the *implementation* of the interface that is the function reference. The capture object with this implementation as a method is then shared by everything that's assigned to a function reference (doesn't need to be the same one). So one instance will be allocated each time the function is entered.</div><div dir="auto">This is the general case. For some very specific cases there can be optimizations that can work without allocations, but that's a topic for the future. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>