Computer Chess Club Archives


Search

Terms

Messages

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

Author: Jon Dart

Date: 09:34:49 02/21/01

Go up one level in this thread


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. 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. Furthermore virtual functions are
slower to call than regular functions, due to the extra indirection.

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.

--Jon



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.