[fpc-pascal] Caller agnostic procedure variables
Sven Barth
pascaldragon at googlemail.com
Tue Feb 15 11:15:04 CET 2022
Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Di., 15. Feb. 2022, 08:34:
>
>
> > On Feb 15, 2022, at 2:09 PM, Michael Van Canneyt via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> > I've answered this question before:
> >
> > The "Reference to procedure" that will be part of anonymous
> functionswill do this for you.
>
> I'm sorry I forgot! This thing keeps coming up for me and driving me nuts
> but I knew I asked in passing before.
>
> So "reference to procedure" are going to be the new standard? To extend my
> example it would look like this? I please remind me, is there a closure
> involved which is capturing state and adding overhead?
>
It contains a capture object that backs the method.
If nothing is captured and the right hand side is a direct function or
method pointer then the compiler could in principle create something that
is essentially static to avoid allocations, but that would be a future
optimization.
> I'm curious what this type actually is also, maybe a dispatch table which
> wraps the existing types or is it something totally new?
>
A function reference is essentially a reference counted interface with a
single method named "Invoke".
And before you ask: no, we're not going to add yet another type that
combines all four when a function reference does that perfectly well
already even if it might be more expensive (note: it's not the call that is
that much more expensive, but the creation).
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20220215/ab40b9ad/attachment.htm>
More information about the fpc-pascal
mailing list