X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftt.cpp;h=f598e3bf1318d4a57e7368d5e9b18a284f86e56b;hp=b730dbeb63bafd6adc78424f8aba0ceb3983a22d;hb=927f1b0bd30a5b2cfdcdf163f26f528738509064;hpb=23db43e698cfc697779a708f1dea43496c549c1d diff --git a/src/tt.cpp b/src/tt.cpp index b730dbeb..f598e3bf 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "tt.h" @@ -54,25 +55,26 @@ void TranspositionTable::set_size(size_t mbSize) { size_t newSize = 1024; - // Transposition table consists of clusters and - // each cluster consists of ClusterSize number of TTEntries. - // Each non-empty entry contains information of exactly one position. - // newSize is the number of clusters we are going to allocate. - while ((2 * newSize) * sizeof(TTCluster) <= (mbSize << 20)) + // Transposition table consists of clusters and each cluster consists + // of ClusterSize number of TTEntries. Each non-empty entry contains + // information of exactly one position and newSize is the number of + // clusters we are going to allocate. + while (2ULL * newSize * sizeof(TTCluster) <= (mbSize << 20)) newSize *= 2; - if (newSize != size) + if (newSize == size) + return; + + size = newSize; + delete [] entries; + entries = new (std::nothrow) TTCluster[size]; + if (!entries) { - size = newSize; - delete [] entries; - entries = new TTCluster[size]; - if (!entries) - { - std::cerr << "Failed to allocate " << mbSize - << " MB for transposition table." << std::endl; - Application::exit_with_failure(); - } + std::cerr << "Failed to allocate " << mbSize + << " MB for transposition table." << std::endl; + exit(EXIT_FAILURE); } + clear(); } @@ -106,7 +108,7 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, tte = replace = first_entry(posKey); for (int i = 0; i < ClusterSize; i++, tte++) { - if (!tte->key() || tte->key() == posKey32) // empty or overwrite old + if (!tte->key() || tte->key() == posKey32) // Empty or overwrite old { // Preserve any existing ttMove if (m == MOVE_NONE) @@ -116,7 +118,8 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, return; } - if (i == 0) // Replacing first entry is default and already set before entering for-loop + // Replacing first entry is default and already set before entering for-loop + if (i == 0) continue; c1 = (replace->generation() == generation ? 2 : 0);