![]() ![]() All the parameters are already loaded in to EAX, EDX and ECX. But why is it using the XCHG instruction in the first place? Well, we are in between a method call. If you know the “XCHG mem,reg” instruction, then you also know that it has an implicit “CPU LOCK” that slows down the method call a lot. This is very slow as you can see in the table above. Xchg ,eax // swap the object ref on the stack with the method address Mov eax, // get the “Test” VMT method address Push eax // save the object reference on the stack This helper converts the “MyIntf” interface reference in the call “MyIntf.Test()” to the object reference behind the interface and then jumps to the virtual method.Īdd eax,-$0C // convert the interface reference to the object reference ![]() The compiler will generate a helper function for the interface method “Test”. TTest = class(TInterfacedObject, IMyInterface) But why is that? Sure, the virtual method call costs some time, but comparing it with the difference of a normal static and virtual method call shows that the timings diverge too much. ![]() Calling a virtual method through an interface always was a lot slower than calling a static method through an interface.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |