Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: C and C++ --- NPS

Author: Gerd Isenberg

Date: 16:52:40 12/24/02

Go up one level in this thread


On December 24, 2002 at 05:29:47, David Rasmussen wrote:

>On December 23, 2002 at 21:33:50, Matt Taylor wrote:
>
>>
>>The biggest hit you take in C++ is virtual functions, and inevitably people use
>>them. The virtual functions are very damaging due to the fact that they're
>>implemented with a function pointer, and at the machine level it translates into
>>an indirect call. The indirect calls branch mispredict because the CPU can't
>>figure out ahead-of-time where you're calling to, and branch mispredicts are
>>expensive.
>>
>>Unfortunately, not using virtual functions (mostly) defeats the benefits you
>>would get from OO here.
>>
>
>First of all, that is a poor understanding of OO.
>Secondly, OO isn't the only virtue of C++. By far.
>
>You would only use virtual functions when you need polymorphism. And if you
>wanted to do that without virtual functions, you would need some other form of
>dispatch such as a switch statement. Many different tests shows that a function
>call and a switch statement isn't faster than a virtual function call. In fact
>it is slower.
>All of this doesn't matter, as there is no obligation to use virtual functions
>in a chess program to use C++ successfully.

Hi David,

what about this? A set of eval classes with same size and memory layout, only
implementing game state specialized virtual eval functions and an abstact base
with all generalized stuff. Simply setting vptr to the desired vtable in an eval
singleton, depending on the game state ;-)

I guess not the dogmatic OO-manner, but wouldn't it be nice to have such a
chamaeleon object?

Regards,
Gerd

>
>>If you convert to C++ without using virtual functions, you probably won't take
>>much of a hit at all. Personally, I've never seen a -need- to convert to C++.
>
>I see no need to use an inferior language to express the same thing for no gain
>at all. C++ gives my type safety, better I/O and a lot more.
>
>>I
>>can implement my OO in C, and it simplifies linking because C doesn't have name
>>mangling.
>>
>
>Is that an issue? It hasn't been an issue for me at all.
>
>/David



This page took 0.03 seconds to execute

Last modified: Thu, 07 Jul 11 08:48:38 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.