summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
089e54c)
Transposition table consists of a power of 2
number of TTCluster entries.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
#include <cstring>
#include <iostream>
#include <cstring>
#include <iostream>
#include "tt.h"
TranspositionTable TT; // Our global transposition table
#include "tt.h"
TranspositionTable TT; // Our global transposition table
/// TranspositionTable::set_size() sets the size of the transposition table,
/// TranspositionTable::set_size() sets the size of the transposition table,
-/// measured in megabytes.
+/// measured in megabytes. Transposition table consists of a power of 2 number of
+/// TTCluster and each cluster consists of ClusterSize number of TTEntries. Each
+/// non-empty entry contains information of exactly one position.
void TranspositionTable::set_size(size_t mbSize) {
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 and newSize is the number of
- // clusters we are going to allocate.
- while (2ULL * newSize * sizeof(TTCluster) <= (mbSize << 20))
- newSize *= 2;
+ size_t newSize = 1ULL << last_1((mbSize << 20) / sizeof(TTCluster));
if (newSize == size)
return;
if (newSize == size)
return;
size = newSize;
delete [] entries;
entries = new (std::nothrow) TTCluster[size];
size = newSize;
delete [] entries;
entries = new (std::nothrow) TTCluster[size];
if (!entries)
{
std::cerr << "Failed to allocate " << mbSize
<< "MB for transposition table." << std::endl;
exit(EXIT_FAILURE);
}
if (!entries)
{
std::cerr << "Failed to allocate " << mbSize
<< "MB for transposition table." << std::endl;
exit(EXIT_FAILURE);
}
+
+ clear(); // operator new is not guaranteed to initialize memory to zero