[fpc-pascal] Traits Proposal

Sven Barth pascaldragon at googlemail.com
Sun Feb 14 19:14:34 CET 2021


Am 14.02.2021 um 19:07 schrieb Ryan Joseph via fpc-pascal:
>
>> On Feb 14, 2021, at 9:55 AM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> No, interfaces by *themselves* don't mean that. An interface instance is merely a shifted Self pointer that points to the static VMT of which the entries correct the Self pointer again upon the method call. This can be seen in GetInterfaceByEntry in rtl/inc/objpas.inc (the core function dealing with the casting of class to interface).
> Remind me again, what happens when you cast a class to an interface? It's a runtime check with GetInterfaceByEntry?
It's a runtime conversion, but normally you don't do the conversion for 
every method call, but instead cache the interface (or work solely with 
the interface), thus the performance impact through the conversion 
amortizes (and again, there's so memory allocation by the conversion 
itself, of course if the interface getter in case of a interface 
delegation does a lazy initialization that's different, but the 
conversion itself does not require an allocation).

Regards,
Sven


More information about the fpc-pascal mailing list