Author: Hristo
Date: 23:47:22 11/24/03
Go up one level in this thread
On November 25, 2003 at 02:27:19, Russell Reagan wrote: >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. You are absolutely correct. I was thinking of the same thing, but thought it would be too much to explain ... >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 This would do just nicely (the reserve() function) and if the vectors don't get deallocated too often, if possible never, then the penalty for their construction and setup is = 0. >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. > Yup .. yup ... ;-) >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. Or check for the available space in the vector and do a batch insertions without using push_back. > >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). Amen. > >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 is the hairy part. It can certainly be done, but one has to get intimate with the particular stl implementation and specifically the allocator objects. ;-) The memory will most likely stay allocated, but might be re-used by another object. Cheers, Hristo
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.