From 3f3f991f108a0698b67f4516640ee925fc442ba9 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 3 Oct 2011 00:07:32 +0000 Subject: [PATCH] basic use of allocators implemented. [SVN r74662] --- .../index/rtree/node/node_default.hpp | 38 +++++++++--- .../node/node_default_static_variant.hpp | 21 +++++++ .../index/rtree/node/node_default_variant.hpp | 60 ++++++++++++++++--- 3 files changed, 105 insertions(+), 14 deletions(-) diff --git a/include/boost/geometry/extensions/index/rtree/node/node_default.hpp b/include/boost/geometry/extensions/index/rtree/node/node_default.hpp index 48131a1e3..7057df708 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_default.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_default.hpp @@ -253,7 +253,15 @@ struct create_node< { static inline typename node::type * apply(Allocators & allocators) { - return new internal_node_poly(); + //return new internal_node_poly(); + internal_node_poly * p + = allocators.internal_node_allocator.allocate(1); + + allocators.internal_node_allocator.construct( + p, + internal_node_poly()); + + return p; } }; @@ -265,7 +273,16 @@ struct create_node< { static inline typename node::type * apply(Allocators & allocators) { - return new leaf_poly(); + //return new leaf_poly(); + + leaf_poly * p + = allocators.leaf_allocator.allocate(1); + + allocators.leaf_allocator.construct( + p, + leaf_poly()); + + return p; } }; @@ -288,7 +305,12 @@ struct destroy_node< { static inline void apply(Allocators & allocators, typename node::type * n) { - delete n; + //delete n; + + internal_node_poly * p + = rtree::get< internal_node_poly >(n); + allocators.internal_node_allocator.destroy(p); + allocators.internal_node_allocator.deallocate(p, 1); } }; @@ -300,13 +322,15 @@ struct destroy_node< { static inline void apply(Allocators & allocators, typename node::type * n) { - delete n; + //delete n; + + leaf_poly * p + = rtree::get< leaf_poly >(n); + allocators.leaf_allocator.destroy(p); + allocators.leaf_allocator.deallocate(p, 1); } }; -// To delete variant node one must pass node * -// To delete poly node one must pass internal_node or leaf - }} // namespace detail::rtree }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp b/include/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp index 4d6ef4242..46974f21f 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp @@ -71,6 +71,27 @@ struct visitor type; }; +// allocators + +template +struct allocators +{ + typedef Allocator allocator_type; + typedef typename allocator_type::size_type size_type; + + typedef typename allocator_type::template rebind< + typename node::type + >::other node_allocator_type; + + inline explicit allocators(Allocator alloc) + : allocator(alloc) + , node_allocator(allocator) + {} + + allocator_type allocator; + node_allocator_type node_allocator; +}; + }} // namespace detail::rtree }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp b/include/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp index f98a91a37..e69a1ca7a 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp @@ -147,6 +147,27 @@ element_indexable(std::pair< return el.first; } +// allocators + +template +struct allocators +{ + typedef Allocator allocator_type; + typedef typename allocator_type::size_type size_type; + + typedef typename allocator_type::template rebind< + typename node::type + >::other node_allocator_type; + + inline explicit allocators(Allocator alloc) + : allocator(alloc) + , node_allocator(allocator) + {} + + allocator_type allocator; + node_allocator_type node_allocator; +}; + // create_node template @@ -155,10 +176,20 @@ struct create_node< internal_node_variant > { - static inline typename node::type * apply(Allocators & allocators) + static inline typename node::type * + apply(Allocators & allocators) { - return new typename node::type( - internal_node_variant() ); + /*return new typename node::type( + internal_node_variant() );*/ + + typename node::type * p + = allocators.node_allocator.allocate(1); + + allocators.node_allocator.construct( + p, + internal_node_variant()); + + return p; } }; @@ -170,8 +201,17 @@ struct create_node< { static inline typename node::type * apply(Allocators & allocators) { - return new typename node::type( - leaf_variant() ); + /*return new typename node::type( + leaf_variant() );*/ + + typename node::type * p + = allocators.node_allocator.allocate(1); + + allocators.node_allocator.construct( + p, + leaf_variant()); + + return p; } }; @@ -185,7 +225,10 @@ struct destroy_node< { static inline void apply(Allocators & allocators, typename node::type * n) { - delete n; + //delete n; + + allocators.node_allocator.destroy(n); + allocators.node_allocator.deallocate(n, 1); } }; @@ -197,7 +240,10 @@ struct destroy_node< { static inline void apply(Allocators & allocators, typename node::type * n) { - delete n; + //delete n; + + allocators.node_allocator.destroy(n); + allocators.node_allocator.deallocate(n, 1); } };