From 68251df645ad8c2d33b7e52adf146eda981938f6 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Sun, 21 Feb 2010 21:32:39 +0100 Subject: [PATCH] Garbage collect the tree by preference when pondering. --- uct/tree.c | 2 +- uct/tree.h | 1 + uct/uct.c | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/uct/tree.c b/uct/tree.c index 9c3b7fc..6127f33 100644 --- a/uct/tree.c +++ b/uct/tree.c @@ -435,7 +435,7 @@ tree_prune(struct tree *dest, struct tree *src, struct tree_node *node, * Prune the subtree if necessary to fit in max_size bytes or * to save time scanning the tree. * Returns the moved node. Only for fast_alloc. */ -static struct tree_node * +struct tree_node * tree_garbage_collect(struct tree *tree, unsigned long max_size, struct tree_node *node) { assert(tree->nodes && !node->parent && !node->sibling); diff --git a/uct/tree.h b/uct/tree.h index 41c9f77..d954057 100644 --- a/uct/tree.h +++ b/uct/tree.h @@ -122,6 +122,7 @@ void tree_merge(struct tree *dest, struct tree *src); void tree_normalize(struct tree *tree, int factor); struct tree_node *tree_get_node(struct tree *tree, struct tree_node *node, coord_t c, bool create); +struct tree_node *tree_garbage_collect(struct tree *tree, unsigned long max_size, struct tree_node *node); void tree_promote_node(struct tree *tree, struct tree_node **node); bool tree_promote_at(struct tree *tree, struct board *b, coord_t c); diff --git a/uct/uct.c b/uct/uct.c index 4d2ddb3..29a7dbe 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -366,6 +366,12 @@ spawn_thread_manager(void *ctx_) uct_halt = 0; + /* Garbage collect the tree by preference when pondering. */ + if (u->pondering && t->nodes && t->nodes_size > t->max_tree_size/2) { + unsigned long temp_size = (MIN_FREE_MEM_PERCENT * t->max_tree_size) / 100; + t->root = tree_garbage_collect(t, temp_size, t->root); + } + /* Spawn threads... */ for (int ti = 0; ti < u->threads; ti++) { struct spawn_ctx *ctx = malloc(sizeof(*ctx)); -- 2.11.4.GIT