[fpc-pascal] Caller agnostic procedure variables
Sven Barth
pascaldragon at googlemail.com
Wed Feb 16 07:57:51 CET 2022
Ryan Joseph via fpc-pascal <fpc-pascal at 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 at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20220216/8388689e/attachment.htm>
More information about the fpc-pascal
mailing list