Some performance questions

Jarrett Billingsley jarrett.billingsley at gmail.com
Mon Feb 2 16:49:30 PST 2009


On Mon, Feb 2, 2009 at 4:55 PM, grauzone <none at example.net> wrote:
> I agree. Of course using an interface to call a method always requires a
> virtual method call. It's even slower than a virtual method call, because it
> needs to convert the interface reference into an object reference.
>
> But he still could call the method in question directly. Implementing an
> interface can be useful to enforce a contract. You can't do that with
> structs.

What's the point of implementing an interface unless you plan on
passing instances of that class to something that expects an interface
reference?  ;)

> Code compiled in debug mode (or was it not-release mode) also calls the code
> to check the invariant, even if you didn't define one. I guess this can make
> calling struct methods much faster than object methods.

Invariants (as well as in/out contracts and assertions) are turned off
in release mode.  FWIW, struct methods also do an "assert(this !is
null);" in debug mode, so they're sort of doing an invariant check.
But struct methods are never virtual, so yes, they will in general be
faster.


More information about the Digitalmars-d-learn mailing list