On 2009-09-28 15:36:05 -0400, bearophile <bearophileh...@lycos.com> said:

Compiled with DMD the running time seems about unchanged. I have no idea why. Maybe some of you can tell me.

If I recall correctly, implementing an interface adds a variable to an class which contains a pointer to that interface's vtable implementation for that particular class. An interface pointer points to that variable inside the object instead (not at the beginning of the object allocated space), and calling a function on it involves dereferencing the interface's vtable, and calling the right function. Obtaining the real "this" pointer for calling the function involves looking at the first value in the interface's vtable which contains an offset you can substract from the interface pointer to get the object pointer.

So basically, if I recall well how it works, calling a function on an interface reference involves one more substraction than calling a member function a class reference, which is pretty marginal.


--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/

Reply via email to