[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: Virtual methods?
On Fri, 22 Aug 2003, Jan Ekholm wrote:
> >> I was wondering; how much impact on performance do I get if I use a
> >> base class that defines a virutal method "Render" and derive all
> >> "renderable" objects from it? I mean, I'll probably have some loops
> >> calling the "Render" method for each object. Is this too expensive? Any
> >> alternatives?
> >Really. algorithmic optimisation is far more valuable than worrying
> >about a tiny overhead like v-method dispatching.
> So true. Premature optimization is the root bla bla... It probably just
> guarantees that your game is never completed.
I think you are beeing a bit harsh here. Depending on how you approach
things, some people (not me) will argue that virtual methods have an
overhead. Personally I would never hesitate, but what if you want to call
10000 rendering objects pr. frame? Would it be worth the hassle to store a
pointer to the functions instead of relying on virtual methods?
I wouldn't think so, but I was looking forward to some comments that
weren't merely a disregard of any objections to virtual methods.
Also, the original poster clearly have not yet implemented anything. While
you consider eliminating the overhead of a virtual method an optimization
best delayed until actually proven a problem, unless you know that or have
a feeling that it will not actually be a major time "bummer", you should
be entitled to ask and get an usuable answer.
/me puts on his asbestous suit
Mads Bondo Dydensborg. firstname.lastname@example.org
Today, the record companies are saying MP3s are the biggest evil. Tomorrow
they're going to say they're the greatest thing when they figure
- Gene Kan, Gnutella developer