From f008de5b04df3c8f6735e5cb561206b52bc4e533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 23 Sep 2019 20:49:12 +0200 Subject: [PATCH] searchtree with BlockAllocator (again) --- libsrc/gprim/adtree.hpp | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/libsrc/gprim/adtree.hpp b/libsrc/gprim/adtree.hpp index 997443fb..aa17c474 100644 --- a/libsrc/gprim/adtree.hpp +++ b/libsrc/gprim/adtree.hpp @@ -404,43 +404,23 @@ public: nchilds = 0; } - void DeleteChilds () + void DeleteChilds (BlockAllocator & ball) { if (left) { - left->DeleteChilds(); - delete left; + left->DeleteChilds(ball); + ball.Free(left); left = NULL; } if (right) { - right->DeleteChilds(); - delete right; + right->DeleteChilds(ball); + ball.Free(right); right = NULL; } } - - // friend class T_ADTree; - - /* - // slow without blockallocator !!!!! - - static BlockAllocator ball; - void * operator new(size_t) - { - return ball.Alloc(); - } - - void operator delete (void * p) - { - ball.Free(p); - } - */ }; -// template -// BlockAllocator T_ADTreeNode :: ball(sizeof (T_ADTreeNode)); - template @@ -451,20 +431,22 @@ public: Point cmin, cmax; // NgArray*> ela; ClosedHashTable*> ela; + + BlockAllocator ball{sizeof(T_ADTreeNode)}; public: T_ADTree (Point acmin, Point acmax) { cmin = acmin; cmax = acmax; - root = new T_ADTreeNode; + root = new (ball.Alloc()) T_ADTreeNode; root->sep = (cmin[0] + cmax[0]) / 2; } ~T_ADTree () { - root->DeleteChilds(); - delete root; + root->DeleteChilds(ball); + ball.Free(root); } void Insert (Point p, T pi) @@ -514,8 +496,7 @@ public: } - next = new T_ADTreeNode; - // memcpy (next->data, p, dim * sizeof(float)); + next = new (ball.Alloc()) T_ADTreeNode; next->data = p; next->pi = pi; next->sep = (bmin[dir] + bmax[dir]) / 2;