[fpc-pascal] Traits Proposal
Sven Barth
pascaldragon at googlemail.com
Tue Feb 16 07:41:54 CET 2021
Am 14.02.2021 um 19:22 schrieb Ryan Joseph via fpc-pascal:
>
>> On Feb 14, 2021, at 11:14 AM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> 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).
> For default properties no conversion needs to take place even because the compiler can simply find the correct method and return a modified self which points to the struct, like "self.fMyRec" in the example below. In this case the interface doesn't really do anything does it? I think the VMT table is modified and you should probably use CORBA interface unless you want reference counting and extra baggage when you instantiate the class (I assume). If we use records then the memory should be unified (which is good) and with CORBA interfaces no significant baggage during instantiation. Correct me where I'm wrong please.
Again, the point of the interface would be to control which methods and
properties of the delegated type would be available. Also it would
allow for seamless integration with the RTTI as it's possible to query
the implemented interface of a class and to retrieve a reference to it,
thus it would be possible to access this at runtime as well.
The compiler will generate a VMT for the interface with method thunks
that adjust the Self pointer so that it works correctly. The
GetInterfaceByEntry function uses this static data to generate an
adjusted Self value that callers can use.
Also for the difference between COM and raw interfaces the only real
difference is that a call to _AddRef will be inserted. But I agree that
it should also work with raw interfaces (if it doesn't already).
Regards,
Sven
More information about the fpc-pascal
mailing list