Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: C++ programmers: the price of syntactic sugar

Author: Pat King

Date: 06:28:24 02/22/01

Go up one level in this thread


On February 21, 2001 at 12:34:49, Jon Dart wrote:

>On February 20, 2001 at 16:17:21, Pat King wrote:
>
>>For what it's worth, a small tale of woe:
>>
>>In accordance with Scott Meyers' "Effective C++" item 47 (don't access
>>uninitialized objects), I created a "guard" class to make sure that my board was
>>initialized as I intended.
>>
>>//board.h
>>class  APiece{...};           //many abstract virtual functions
>>inline APiece* &Board(int i); //meant to be used as if declared Board[120]
>>inline APiece* Empty();       //returns pointer to do-nothing class
>>
>
>I predict that you find using piece declared as a class causes a significant
>performance penalty.

LOL that one doesn't take the psychic ability of the Great Kreskin.


> You will wind up creating a lot of such objects. If created
>on the heap, you will have the overehad of malloc() plus the cost of calling
>your object constructor once per instance.

I create exactly 32 objects at startup. I don't destroy and rebuild with
captures and unmoves. So your point is true, but irrelavant.

>Furthermore virtual functions are
>slower to call than regular functions, due to the extra indirection.
>

True, but for my humble program worth the decrease in complexity. I've come a
lot farther with Z2k than with the previous versions of Zotron, and I believe
it's do to the OO approach and the elimination of as many "if" and "switch"
statements as possible.

>In my opinion, backed by experience, you'd be better off using a primitive type
>such as "int" for piece values. Not as elegant perhaps but speed counts in a
>chess program.

Getting it working counts more. Zotron will admittedly never be as fast as a C
program, but I never planned for it to be a world beater. It's just something
for me to tinker with.

>
>--Jon

Pat



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

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