[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: Virtual methods?



On Fri, 22 Aug 2003 madsdyd@challenge.dk wrote:

>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?

Sure, but can you prove the contrary? That open source game developers
that micromanage optimizations before the game has even been started have
a chance of actually getting something out? The Linux world has 10000
games, of which 100 can be considered complete. I've added a few games to
the 9900 dead ones in my days.

>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.

Well, do a little test. Create a class hierarchy of som classes classes
that inherit a common class, maybe a few other ones inheriting those too,
and time it all. Then redo it using some other way. Should take an hour or
so to setup, compile, test and draw conclusions.

>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.

Sure. I was far out of line and I apologize.

--
Somewhere around the place I've got an unfinished short story about
Schroedinger's Dog; it was mostly moaning about all the attention the cat
was getting.
                                   -- Terry Pratchett, alt.fan.pratchett