basic use of allocators implemented.

[SVN r74662]
This commit is contained in:
Adam Wulkiewicz
2011-10-03 00:07:32 +00:00
parent a1e7923de2
commit 3f3f991f10
3 changed files with 105 additions and 14 deletions

View File

@@ -253,7 +253,15 @@ struct create_node<
{
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 @@ struct create_node<
{
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 @@ struct destroy_node<
{
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 @@ struct destroy_node<
{
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

View File

@@ -71,6 +71,27 @@ struct visitor<Value, Parameters, Box, node_default_static_variant_tag, IsVisita
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

View File

@@ -147,6 +147,27 @@ element_indexable(std::pair<
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 @@ struct create_node<
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 @@ struct create_node<
{
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 @@ struct destroy_node<
{
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 @@ struct destroy_node<
{
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);
}
};