[fpc-pascal] Traits Proposal

Sven Barth pascaldragon at googlemail.com
Wed Feb 17 14:17:23 CET 2021


Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Mi., 17. Feb. 2021, 02:21:

>
>
> > On Feb 16, 2021, at 3:35 PM, Benito van der Zander via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> > But it is not calling the method, it is calling the wrapper function
>
> what you say wrapper function do you mean the ref counting functions when
> you pass around the interface?
>

No. With wrapper function he means the thunks that are responsible for
adjusting the instance pointer of the interface to the instance pointer of
the class before jumping to the method of the class.

I guess for ref counting you're supposed to cast the class to the interface
> (which is an expensive runtime lookup) and then pass that thing around?
> That seems like a crazy way to get ref counting plus you need to cast the
> interface back to the class if you want to call other methods? I still
> don't get this pattern. ARC should be handled by the compiler and be on the
> class itself, not some additional object you need to create and then store.
>

I have the feeling that you don't really know how interfaces work.
ARC would have the exact same penalty as the reference counting of
interfaces, because that is essentially what the compiler would use: call
some function that increases/decreases the reference count of the instance.
That is *exactly* what is done for interfaces.

Also the interface is not created. It's part of the class instance. You
simply have a pointer sized value that points to that. In the ideal
situation of *only* working with the interface you can simply forget the
class instance, cause the class will be freed once the reference count
reached 0. Thus there will be *no* additional storage involved.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210217/06ca9564/attachment.htm>


More information about the fpc-pascal mailing list