Slow performance compared to C++, ideas?
Jonathan M Davis
jmdavisProg at gmx.com
Sat Jun 1 14:08:45 PDT 2013
On Saturday, June 01, 2013 22:43:32 Marco Leise wrote:
> Am Sat, 01 Jun 2013 11:22:41 -0700
>
> schrieb Walter Bright <newshound2 at digitalmars.com>:
> > On 5/30/2013 7:56 PM, Andrei Alexandrescu wrote:
> > > On 5/30/13 9:26 PM, finalpatch wrote:
> > >> https://dl.dropboxusercontent.com/u/974356/raytracer.d
> > >> https://dl.dropboxusercontent.com/u/974356/raytracer.cpp
> > >
> > > Manu's gonna love this one: make all methods final.
> >
> > I have another suggestion. class Sphere and class Ray should be structs.
> > Neither class uses polymorphism in any way, so there's no reason to make
> > them classes with virtual functions.
>
> Yes, that's the easiest (and for Ray the right(tm)) way to get
> rid of virtual functions. But, I think it is safe to assume
> that there will be different object classes in the big picture.
If you don't need polymorphism, then in general, you shouldn't use a class
(though sometimes it might make sense simply because it's an easy way to get a
reference type). Where it becomes more of a problem is when you need a few
polymorphic functions and a lot of non-polymorphic functions (e.g. when a
class has a few methods which get overridden and then a lot of properties
which it makes no sense to override). In that case, you have to use a class,
and then you have to mark a lot of functions as final. This is what folks like
Manu and Don really don't like, particularly when they're in environments
where the extra cost of the virtual function calls actually matters.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list