[fpc-pascal] How is interface variable implemented?
Sven Barth
pascaldragon at googlemail.com
Sat Aug 25 13:08:21 CEST 2018
Dennis <dec12 at avidsoft.com.hk> schrieb am Fr., 24. Aug. 2018, 13:11:
> The run results:
> Object call Time Taken Seconds: 2.1899964194744825E-001
> Interface call Time Taken Seconds: 2.7999999001622200E-001
>
> so, the time difference is about 27%
>
>
> My question is, where is this extra time spent?
>
> I am assuming an interface variable has a table with entries storing (
> pointer to the object instance AND an offset of method address in the
> Virtual Method Table of that object.)
>
> Am I correct?
>
Using an interface is always calling virtual methods.
It's however a table that contains pointers to compiler generated wrappers
that adjust the Self Pointer and call the correct method.
> What is the memory occupied by the interface variable?
> I know the sizeof(i) = 8 (in 64 bit windows), but what is the size of
> the instance?
>
The instance is essentially only the VMT, cause for interfaces implemented
by FPC classes the interface variable points to a shifted Self pointer that
is "fixed" c the wrappers mentioned above.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180825/c47fcd3e/attachment.html>
More information about the fpc-pascal
mailing list