Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74662 - sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node
From: adam.wulkiewicz_at_[hidden]
Date: 2011-10-02 20:07:33


Author: awulkiew
Date: 2011-10-02 20:07:32 EDT (Sun, 02 Oct 2011)
New Revision: 74662
URL: http://svn.boost.org/trac/boost/changeset/74662

Log:
basic use of allocators implemented.
Text files modified:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default.hpp | 38 ++++++++++++++++++++----
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp | 21 ++++++++++++++
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp | 60 +++++++++++++++++++++++++++++++++++----
   3 files changed, 105 insertions(+), 14 deletions(-)

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default.hpp 2011-10-02 20:07:32 EDT (Sun, 02 Oct 2011)
@@ -253,7 +253,15 @@
 {
     static inline typename node<Value, Parameters, Box, Tag>::type * apply(Allocators & allocators)
     {
- return new internal_node_poly<Value, Parameters, Box, Tag>();
+ //return new internal_node_poly<Value, Parameters, Box, Tag>();
+ internal_node_poly<Value, Parameters, Box, Tag> * p
+ = allocators.internal_node_allocator.allocate(1);
+
+ allocators.internal_node_allocator.construct(
+ p,
+ internal_node_poly<Value, Parameters, Box, Tag>());
+
+ return p;
     }
 };
 
@@ -265,7 +273,16 @@
 {
     static inline typename node<Value, Parameters, Box, Tag>::type * apply(Allocators & allocators)
     {
- return new leaf_poly<Value, Parameters, Box, Tag>();
+ //return new leaf_poly<Value, Parameters, Box, Tag>();
+
+ leaf_poly<Value, Parameters, Box, Tag> * p
+ = allocators.leaf_allocator.allocate(1);
+
+ allocators.leaf_allocator.construct(
+ p,
+ leaf_poly<Value, Parameters, Box, Tag>());
+
+ return p;
     }
 };
 
@@ -288,7 +305,12 @@
 {
     static inline void apply(Allocators & allocators, typename node<Value, Parameters, Box, Tag>::type * n)
     {
- delete n;
+ //delete n;
+
+ internal_node_poly<Value, Parameters, Box, Tag> * p
+ = rtree::get< internal_node_poly<Value, Parameters, Box, Tag> >(n);
+ allocators.internal_node_allocator.destroy(p);
+ allocators.internal_node_allocator.deallocate(p, 1);
     }
 };
 
@@ -300,13 +322,15 @@
 {
     static inline void apply(Allocators & allocators, typename node<Value, Parameters, Box, Tag>::type * n)
     {
- delete n;
+ //delete n;
+
+ leaf_poly<Value, Parameters, Box, Tag> * p
+ = rtree::get< leaf_poly<Value, Parameters, Box, Tag> >(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

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp 2011-10-02 20:07:32 EDT (Sun, 02 Oct 2011)
@@ -71,6 +71,27 @@
     typedef static_visitor<> type;
 };
 
+// allocators
+
+template <typename Value, typename Parameters, typename Box, typename Allocator>
+struct allocators<Value, Parameters, Box, node_default_static_variant_tag, Allocator>
+{
+ typedef Allocator allocator_type;
+ typedef typename allocator_type::size_type size_type;
+
+ typedef typename allocator_type::template rebind<
+ typename node<Value, Parameters, Box, node_default_static_variant_tag>::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

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp 2011-10-02 20:07:32 EDT (Sun, 02 Oct 2011)
@@ -147,6 +147,27 @@
     return el.first;
 }
 
+// allocators
+
+template <typename Value, typename Parameters, typename Box, typename Allocator>
+struct allocators<Value, Parameters, Box, node_default_variant_tag, Allocator>
+{
+ typedef Allocator allocator_type;
+ typedef typename allocator_type::size_type size_type;
+
+ typedef typename allocator_type::template rebind<
+ typename node<Value, Parameters, Box, node_default_variant_tag>::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 <typename Allocators, typename Value, typename Parameters, typename Box, typename Tag>
@@ -155,10 +176,20 @@
     internal_node_variant<Value, Parameters, Box, Tag>
>
 {
- static inline typename node<Value, Parameters, Box, Tag>::type * apply(Allocators & allocators)
+ static inline typename node<Value, Parameters, Box, Tag>::type *
+ apply(Allocators & allocators)
     {
- return new typename node<Value, Parameters, Box, Tag>::type(
- internal_node_variant<Value, Parameters, Box, Tag>() );
+ /*return new typename node<Value, Parameters, Box, Tag>::type(
+ internal_node_variant<Value, Parameters, Box, Tag>() );*/
+
+ typename node<Value, Parameters, Box, Tag>::type * p
+ = allocators.node_allocator.allocate(1);
+
+ allocators.node_allocator.construct(
+ p,
+ internal_node_variant<Value, Parameters, Box, Tag>());
+
+ return p;
     }
 };
 
@@ -170,8 +201,17 @@
 {
     static inline typename node<Value, Parameters, Box, Tag>::type * apply(Allocators & allocators)
     {
- return new typename node<Value, Parameters, Box, Tag>::type(
- leaf_variant<Value, Parameters, Box, Tag>() );
+ /*return new typename node<Value, Parameters, Box, Tag>::type(
+ leaf_variant<Value, Parameters, Box, Tag>() );*/
+
+ typename node<Value, Parameters, Box, Tag>::type * p
+ = allocators.node_allocator.allocate(1);
+
+ allocators.node_allocator.construct(
+ p,
+ leaf_variant<Value, Parameters, Box, Tag>());
+
+ return p;
     }
 };
 
@@ -185,7 +225,10 @@
 {
     static inline void apply(Allocators & allocators, typename node<Value, Parameters, Box, Tag>::type * n)
     {
- delete n;
+ //delete n;
+
+ allocators.node_allocator.destroy(n);
+ allocators.node_allocator.deallocate(n, 1);
     }
 };
 
@@ -197,7 +240,10 @@
 {
     static inline void apply(Allocators & allocators, typename node<Value, Parameters, Box, Tag>::type * n)
     {
- delete n;
+ //delete n;
+
+ allocators.node_allocator.destroy(n);
+ allocators.node_allocator.deallocate(n, 1);
     }
 };
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk