Author: Scott Gasch
Date: 20:04:55 06/08/02
Go up one level in this thread
On June 08, 2002 at 20:55:17, Jon Dart wrote: >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. BTW, with MSVC you can do __forceinline and it will always do it. >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. Yes my #1 complaint about C++ is a weakness with myself -- not the language. I don't know exactly how classes are layed out in memory... I guess the data and some kind of table of function pointers. But especially when we get into inheritance and polymorphism... I just can't follow the mess. I like C because I know exactly what's going on, where each variable lives in memory, and what I'm doing with my code. >There are other reasons why objects can be slower, but these are some of them. > >--Jon Scott
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.