[fpc-pascal] Interface performance

Ryan Joseph ryan at thealchemistguild.com
Fri Nov 11 16:28:30 CET 2016

> 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)." 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.

It seems trivial to be avoiding a string lookup but in some tight loops and sorting functions the call to Supports is taking far more time than the actual sorting so it’s clearly not a good solution.

More on this tomorrow until I give up for certain. :)

	Ryan Joseph

More information about the fpc-pascal mailing list