[fpc-pascal] Creating capturers

Sven Barth pascaldragon at googlemail.com
Sat Nov 4 10:22:29 CET 2023


Hairy Pixels <genericptr at gmail.com> schrieb am Sa., 4. Nov. 2023, 01:42:

>
>
> > On Nov 3, 2023, at 8:31 PM, Sven Barth <pascaldragon at googlemail.com>
> wrote:
> >
> > If you need a catch all type, then you should use function references.
> There is no need to invent yet another type.
> > The only thing it can not handle is the assignment of nested function
> pointers (in contrast to nested functions directly), because they can only
> ever be used in a function that is below the one where the nested function
> was assigned which is not a guaranteed property for function references.
> >
>
> not always because it creates a heap allocated interfaces for every
> function they're used in, even if it doesn't escape the scope. Maybe this
> was fine for Delphi but they can't be used for anything real time outside
> of GUI apps.
>

Then don't assign them every "frame". If you just keep them around then
they aren't more expensive than a virtual method call.
And any other mechanism would involve the heap as well, because that's how
anonymous functions that capture variables work and thus anything that
wants to store them must play by the same rules. There won't be any changes
there.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20231104/e802fc20/attachment-0001.htm>


More information about the fpc-pascal mailing list