Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: c++ code question

Author: Russell Reagan

Date: 23:27:19 11/24/03

Go up one level in this thread


On November 25, 2003 at 01:23:36, Hristo wrote:

>vectors will not check out of bounds conditions when used in such way.
>However if the push_back is used then the vector will grow itself automatically,
>but performance would go out of the window.

I'm not so sure that performance should suffer very much.

You could have a stack of move lists (a vector of vectors), one for each ply.
For the first 64 plies (or whatever number you'd like), you could use the
reserve() member function of a vector to make sure that there are enough
reserved move lists for the upcoming search, and that each move list contains
enough reserved elements so that you will rarely have to do any reallocation.

The only overhead involved would be an extra conditional to test that you don't
need to reallocate during each push_back(). That conditional should fail the
vast majority of the time, so it should be easy for the CPU to predict.

Maybe it will need to reallocate sometimes, but that is a small price to pay for
not having to worry about memory management or array overruns (something I've
been bitten hard by in the past in my own chess program).

As far as clearing the vector, I believe all that will happen is that the
internal size of the vector will go to zero, but the memory remains allocated.
If this isn't how vector works, it would be pretty easy to write your own move
list container that does this.



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.