Author: Jon Dart
Date: 17:55:17 06/08/02
Go up one level in this thread
On June 08, 2002 at 15:13:09, Russell Reagan wrote: >My solution was to use classes for almost everything. Position, move, square, >piece, castling rights, whatever. The result is that each of those objects knows >how to handle it's duties and it doesn't have to worry about other objects. Each >of my objects has a nice toString() method that I really enjoy. > >As far as speed is concerned, most of the methods are inlined anyway, so it will >act just like a C struct in terms of efficiency. My experience is different. I started out with something close to the "classes for everything" approach, but found that for smaller objects, packing their contents into into 32- or 64-bit ints was significantly faster. You can use macros or inline functions to pack and unpack. Inlining is generally a hint, not a command, to the compiler, so you may find that things you think should be inlined are not, or at least are not always. There are other costs. For example, when initializing an array of objects, many compilers will sit in a loop calling the constructors for each object. If you know, for example, that the initial class data consists of 0 bytes, you could do this with "memset" instead - it will be way faster. There are other reasons why objects can be slower, but these are some of them. --Jon
This page took 0.01 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.