Ryan Joseph via fpc-pascal <fpc-pascal@lists.freepascal.org> schrieb am
Mi., 16. Feb. 2022, 03:14:

>
>
> > On Feb 15, 2022, at 11:09 PM, Sven Barth via fpc-pascal <
> fpc-pascal@lists.freepascal.org> wrote:
> >
> > For a global function the compiler has to generate a wrapper that gets
> rid of the Self parameter of the interface.
> >
>
> 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.
>

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.
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.

Regards,
Sven

>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to