> On Jun 6, 2022, at 2:02 AM, Jonas Maebe via fpc-pascal
> <[email protected]> wrote:
>
> On 2022-06-05 18:20, Anthony Walter via fpc-pascal wrote:
>
>> As the "reference to" feature was recently added to fpc trunk, I'd like to
>> ask if internally there are any penalties (performance perhaps) or drawbacks
>> to using them in place of the more traditional "procedure" and "procedure of
>> object" types?
>
> The downside is that a "reference to" always gets wrapped in a
> reference-counted interface, and hence is much more expensive than a place
> procedural variable ("of object" or not).
First off I didn’t see Anthony’s original email, just like Sven says he doesn’t
see mine. What’s going on here? I’m using a Gmail account because my personal
domain was getting rejected for some reason, is Anthony on Gmail also? We need
to get this fixed I think.
Anytime you assign to a reference it creates this interface wrapped object,
even if you don’t call it. This is of course totally wasteful and in fact makes
references not reliable as a catch-all function pointer type since it comes
with significant runtime overhead.
I think what the compiler needs to do is internally support a variant record
type and switch to the correct function type at runtime. Something like this:
TCallback = record
kind: byte;
case byte of
0: (proc: procedure);
1: (ref: reference to procedure);
2: (nested: procedure is nested);
3: (obj: procedure of object);
end;
Does that sound correct? Personally what I want to see if a catch all type so I
don’t need to make 4 different function aliases for each of FPCs callback types.
However as far as anonymous functions are concerned I was pleased to see that
they can be can be assigned to other function pointer types so I can still use
the feature in many cases.
Regards,
Ryan Joseph
_______________________________________________
fpc-pascal maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal