"shogi"
#endif
);
- printf("debug=1 setboard=0 sigint=0 done=1\n");
+ printf("debug=1 setboard=0 sigint=0 memory=1 done=1\n");
}
else if (strcmp(s, ".") == 0)
{ // periodic update request of analysis info: send stat01 info
{
ok = true;
}
+#if ttblsz
+ else if (strcmp(s, "memory") == 0)
+ {
+ unsigned int mem, size, t = 1;
+ sscanf(sx, "memory %d", &mem);
+ if(mem > 2048) mem = 2048; /* prevent integer overflow for > 2GB hash */
+ size = (mem << 20) / sizeof(struct hashentry) - rehash;
+ while(t <= size/4) t <<= 1;
+ AllocateTT(t);
+ }
+#endif
else if (strcmp(s, "go") == 0)
{
ok = true;
white, white
};
+int
+AllocateTT(int size)
+{
+ int n = sizeof(struct hashentry)*(size + rehash);
+ static int oldSize;
+ int doit = true;
+
+ if(oldSize == size) return use_ttable;
+ oldSize = ttblsize = size;
+
+ if(ttable[0]) free(ttable[0]);
+ if(ttable[1]) free(ttable[1]);
+
+ while (doit && ttblsize > MINTTABLE)
+ {
+ ttable[0] = malloc(n); /* FIXME: cast to the correct type. */
+ ttable[1] = ttable[0] ? malloc(n) : NULL;
+
+ if (!ttable[0] || !ttable[1])
+ {
+ if (!ttable[0])
+ free(ttable[0]);
+
+ if (!ttable[1])
+ free(ttable[1]);
+
+ ttblsize = ttblsize >> 1;
+ n = sizeof(struct hashentry) * (ttblsize + rehash);
+ }
+ else
+ {
+ doit = false;
+ }
+ }
+
+ if (ttblsize <= MINTTABLE)
+ {
+ use_ttable = false;
+ }
+
+ if (use_ttable)
+ {
+ /* CHECKME: is the precedence here correct? */
+ /* ttbllimit = ttblsize << 1 - ttblsize >> 2; */
+ ttbllimit = (ttblsize << 1) - (ttblsize >> 2);
+ }
+ else
+ {
+ ttable[0] = ttable[1] = NULL;
+ }
+
+ return use_ttable;
+}
int
Initialize_data(void)
size_t n;
int i;
char buffer[60];
- int doit = true;
{
small_short x = -1;
if (rehash < 0)
rehash = MAXrehash;
- n = sizeof(struct hashentry)*(ttblsize + rehash);
-
- while (doit && ttblsize > MINTTABLE)
- {
- ttable[0] = malloc(n); /* FIXME: cast to the correct type. */
- ttable[1] = ttable[0] ? malloc(n) : NULL;
-
- if (!ttable[0] || !ttable[1])
- {
- if (!ttable[0])
- free(ttable[0]);
-
- if (!ttable[1])
- free(ttable[1]);
-
- ttblsize = ttblsize >> 1;
- n = sizeof(struct hashentry) * (ttblsize + rehash);
- }
- else
- {
- doit = false;
- }
- }
-
- if (ttblsize <= MINTTABLE)
- {
- use_ttable = false;
- }
-
- if (use_ttable)
- {
- /* CHECKME: is the precedence here correct? */
- /* ttbllimit = ttblsize << 1 - ttblsize >> 2; */
- ttbllimit = (ttblsize << 1) - (ttblsize >> 2);
- }
- else
+ if (!AllocateTT(ttblsize))
{
sprintf(buffer, "Cannot allocate %ld bytes for transposition table",
(long)(2 * n));
dsp->ShowMessage(buffer);
- ttable[0] = ttable[1] = NULL;
}
#endif /* ttblsz */