digitalmars.D.learn - Final class and interface
- "Casper =?UTF-8?B?RsOmcmdlbWFuZCI=?= <shorttail gmail.com> (3/3) Mar 03 2014 Is there any loss in performance instantiating an interface
-
Steven Schveighoffer
(21/24)
Mar 03 2014
On Mon, 03 Mar 2014 21:48:16 -0500, Casper F=C3=A6rgemand
Is there any loss in performance instantiating an interface variable as a final class implementing only that interface, as opposed to a class variable?
Mar 03 2014
On Mon, 03 Mar 2014 21:48:16 -0500, Casper F=C3=A6rgemand <shorttail gma= il.com> = wrote:Is there any loss in performance instantiating an interface variable a=s =a final class implementing only that interface, as opposed to a class ==variable?You mean the difference between: final class C : I {...} // this I i =3D new C; // and this C c =3D new C; ??? The difference in performance is huge. As a final class, no virtual call= s = are needed. In itself, this is not a huge deal, as a virtual call is not= = too much worse than a standard call. However, method calls on the concrete class can be inlined, and an inlin= e = call is generally very quick when compared to any kind of other call. -Steve
Mar 03 2014