[fpc-pascal] Interface performance
jonas.maebe at elis.ugent.be
Fri Nov 11 21:22:58 CET 2016
On 11/11/16 16:28, Ryan Joseph wrote:
>> On Nov 11, 2016, at 8:54 PM, Tony Whyman <tony.whyman at mccallumwhyman.com> wrote:
>> If you go back to the FPC documentation, in the User Guide it says "Objects are stored in memory just as ordinary records with an extra field: a pointer to the Virtual Method Table (VMT)."
That text is about Turbo Pascal-style objects, not about classes.
>> My understanding is that an interface is stored similarly, except that a different VMT is used i.e. that which defines the interface. If you try and assign one to the other by just coercing the type then you will get undefined results.
> I think what I’m trying to do is just not compatible with how interfaces work in FPC then. I’m trying to pass an object (which implements an interface) and then without using “as” or Supports access the interface for that object so I can call its methods. I keep running into crashes and from your description it’s because I only have an object but I need the interface reference which MUST use a string lookup. Casting an object as its interface causes undefined results.
You're passing a class, not an object. Passing a class that implements
an interface to a method that expects that interface should work fine.
Converting a class instance to an interface that it implements is
trivial and always works, it's doing the opposite that is hard and that
requires specific support in the interface.
More information about the fpc-pascal