Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Solving the "constructor" problem in C++

Author: Russell Reagan

Date: 12:43:04 06/12/02

Go up one level in this thread


On June 12, 2002 at 15:29:52, RĂ©mi Coulom wrote:

>You do not have to write a constructor for a class either. Removing your empty
>constructors is probably the best solution, if I guessed what you did correctly.

What about if I had a 'class Move' and did the following:

class MoveList {
    Move  moves[512];
    int   numMoves;
  public:
    // constructors and other methods here
};

Isn't Move's constuctor going to get run 512 times for this, even if I only end
up making use of the first 5 Move's in the array? That seems to be wasteful,
especially if the constructor does something. Even if the constructor does
nothing, it's getting called 512 times. Suppose I used a MoveList in my
alpha-beta function to store the legal moves in. That means that I'm wasting a
function call 512 times FOR EACH NODE I look at. Since a typical search will go
into the millions of nodes, that's 512 million function calls that are
completely wasted, and that's assuming that the constructor does absolutely
nothing.

As for just deleting the default constructor, I believe that in this case where
you have an array of Move, the compiler will give you an error saying that there
is no default constructor for class Move.

Russell



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.