From 216e8cc19555ef38b632cebbfc39022a54cd085f Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 24 Apr 2016 14:28:57 +0200 Subject: [PATCH] Get rid of fixed size array Use std::deque instead because it preserves references to its elements when resizing (std::vector does not). DTZ_table is still an array because it seems its size is fixed and does not depend on TB exsisting files. --- src/syzygy/tbprobe.cpp | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/syzygy/tbprobe.cpp b/src/syzygy/tbprobe.cpp index c57e2c3d..29b5d617 100644 --- a/src/syzygy/tbprobe.cpp +++ b/src/syzygy/tbprobe.cpp @@ -10,6 +10,7 @@ #include #include #include // For std::memset +#include #include #include #include @@ -345,17 +346,13 @@ const Value WDL_to_value[] = { }; const int DTZ_ENTRIES = 64; -const int TBMAX_PIECE = 254; -const int TBMAX_PAWN = 256; const std::string PieceChar = " PNBRQK"; -int TBnum_piece; -int TBnum_pawn; Mutex TB_mutex; std::string TBPaths; -TBEntry_piece TB_piece[TBMAX_PIECE]; -TBEntry_pawn TB_pawn[TBMAX_PAWN]; +std::deque TB_piece; +std::deque TB_pawn; DTZTableEntry DTZ_table[DTZ_ENTRIES]; int Binomial[5][64]; @@ -579,12 +576,8 @@ void HashTable::insert(const std::vector& pieces) Tablebases::MaxCardinality = num; if (hasPawns) { - if (TBnum_pawn == TBMAX_PAWN) { - std::cerr << "TBMAX_PAWN limit too low!" << std::endl; - exit(1); - } - - TBEntry_pawn* ptr = &TB_pawn[TBnum_pawn++]; + TB_pawn.push_back(TBEntry_pawn()); + TBEntry_pawn* ptr = &TB_pawn.back(); // FIXME: What it means this one? if ( !pos.count(BLACK) @@ -599,12 +592,8 @@ void HashTable::insert(const std::vector& pieces) entry = (TBEntry*)ptr; } else { - if (TBnum_piece == TBMAX_PIECE) { - std::cerr << "TBMAX_PIECE limit too low!" << std::endl; - exit(1); - } - - TBEntry_piece* ptr = &TB_piece[TBnum_piece++]; + TB_piece.push_back(TBEntry_piece()); + TBEntry_piece* ptr = &TB_piece.back(); int uniquePieces = 0; for (PieceType pt = PAWN; pt <= KING; ++pt) @@ -1951,10 +1940,10 @@ int probe_dtz(Position& pos, int *success) void Tablebases::free() { - for (int i = 0; i < TBnum_piece; ++i) + for (size_t i = 0; i < TB_piece.size(); ++i) free_wdl_entry(&TB_piece[i]); - for (int i = 0; i < TBnum_pawn; ++i) + for (size_t i = 0; i < TB_pawn.size(); ++i) free_wdl_entry(&TB_pawn[i]); for (int i = 0; i < DTZ_ENTRIES; ++i) @@ -1963,9 +1952,10 @@ void Tablebases::free() DTZ_table[i].entry = nullptr; } + TB_piece.clear(); + TB_pawn.clear(); TBHash.clear(); - TBnum_piece = TBnum_pawn = 0; MaxCardinality = 0; } @@ -2027,7 +2017,7 @@ void Tablebases::init(const std::string& paths) } } - std::cerr << "info string Found " << TBnum_piece + TBnum_pawn << " tablebases" << std::endl; + std::cerr << "info string Found " << TB_piece.size() + TB_pawn.size() << " tablebases" << std::endl; } // Probe the WDL table for a particular position.