Interface vs pure abstract class - speed.

SundayMorningRunner someone at somewhere.com
Sun May 12 11:17:53 PDT 2013


On Sunday, 12 May 2013 at 18:00:10 UTC, Diggory wrote:
> On Sunday, 12 May 2013 at 17:31:22 UTC, SundayMorningRunner 
> wrote:
>> Hello, let's say I have the choice between using an abstract 
>> class or an interface to declare a "plan", a "template" for 
>> the descendants.
>>
>> From the dmd compiler point of view, should I use the abstract 
>> class version (so I guess that for each method call, there 
>> will be a few MOV, in order to extract the relative address 
>> from the vmt before a CALL) or the interface version (are the 
>> CALL directly performed in this case). Are interface faster ? 
>> (to get the address used by the CALL).
>>
>> Thx.
>
> I would expect abstract classes to be slightly faster 
> (certainly they shouldn't be slower), but the difference to be 
> insignificant compared to other factors.
>
> Deriving from an abstract base class is a much stronger 
> relationship than implementing an interface, so it depends on 
> your situation. If your class is a "provider" (eg. it provides 
> some functionality such as being able to receive some event) 
> then an interface makes more sense. If your class is a type of 
> something (eg. a button is a type of gui control) then 
> inheritance makes more sense.

It's ok about the difference between an interface and an abstract
class. My question is really technical: which is the fatest:
to a method from an interface or to the overriden
method of an abstract class ? Think about a context such as audio
DSP, where a method will be called for each buffer during 2 or 3
hours without interuption, and maybe 3 or 4 times per second...


More information about the Digitalmars-d-learn mailing list