Computer Chess Club Archives


Search

Terms

Messages

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

Author: Dann Corbit

Date: 12:59:41 06/12/02

Go up one level in this thread


On June 12, 2002 at 15:43:04, Russell Reagan wrote:

>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.

If the constructor does nothing it is the same as an array of structs declared
auto.  No time is wasted.

>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.

Why do you need more than one movelist?

>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.

There will be no function calls if the constructor does nothing.  Look at the
assembly generated.  With GCC use -S and with MS VC++ or Intel C++ use /Fa

>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.

Broken compiler.



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.