Author: Russell Reagan
Date: 17:54:27 01/22/04
Go up one level in this thread
On January 22, 2004 at 18:06:17, Tord Romstad wrote: >Using dynamic memory for any of the central data structures in a chess program >seems inefficient and unnecessary to me, but I guess you have good reasons to >do so. You can always go the fake dynamic allocation route for a decent compromise. Take C++ std::vector (dynamic array) for instance. You can 'reserve' an amount of memory for it during a non-peak processing time (like right after a game move is made, while you're not searching yet). For instance: std::vector<Move> moveList; // While we are not searching... moveList.reserve(64); // reserve 64 elements worth of memory To add moves in the move generator, just push them onto the end of the vector: while (MovesLeftToGenerate()) moveList.push_back(NextMove()); Usually you won't need all 64 elements to store moves, so you never reallocate. In the event that you do need to, it happens automagically. push_back() just checks whether it has overstepped it's bounds, so the extra cost is a single if statement, which is nothing in the grand scheme of the chess program.
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.