Rosetta 3.5
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
core
graph
unordered_object_pool.hpp
Go to the documentation of this file.
1
// Copyright (C) 2000, 2001 Stephen Cleary
2
//
3
// Distributed under the Boost Software License, Version 1.0. (See
4
// accompanying file LICENSE_1_0.txt or copy at
5
// http://www.boost.org/LICENSE_1_0.txt)
6
//
7
// See http://www.boost.org for updates, documentation, and revision history.
8
// (c) Copyright Rosetta Commons Member Institutions.
9
// (c) This file is part of the Rosetta software suite and is made available under license.
10
// (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
11
// (c) For more information, see http://www.rosettacommons.org. Questions about this can be
12
// (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
13
14
#ifndef BOOST_UNORDERED_OBJECT_POOL_HPP
15
#define BOOST_UNORDERED_OBJECT_POOL_HPP
16
17
#include <
core/graph/unordered_object_pool.fwd.hpp
>
18
19
#ifdef PYROSETTA
20
#include <boost/pool/pool.hpp>
21
#endif
22
23
// boost::pool
24
25
// The following code will be put into Boost.Config in a later revision
26
#if defined(BOOST_MSVC) || defined(__KCC)
27
# define BOOST_NO_TEMPLATE_CV_REF_OVERLOADS
28
#endif
29
30
// The following code might be put into some Boost.Config header in a later revision
31
#ifdef __BORLANDC__
32
# pragma option push -w-inl
33
#endif
34
35
// There are a few places in this file where the expression "this->m" is used.
36
// This expression is used to force instantiation-time name lookup, which I am
37
// informed is required for strict Standard compliance. It's only necessary
38
// if "m" is a member of a base class that is dependent on a template
39
// parameter.
40
// Thanks to Jens Maurer for pointing this out!
41
42
// APL This class differs from the object-pool class in that its destructor does
43
// not invoke the destructors of un-freed objects that are still living in the pool.
44
// For destructors to be called, objects must be explicitly destroyed with a call
45
// to destroy(). The trade-off is hassle for speed. In code where lots of small objects
46
// are being created and destroyed on a regular basis, this class is dramatically
47
// faster.
48
49
namespace
boost {
50
51
// T must have a non-throwing destructor
52
template
<
typename
T,
typename
UserAllocator>
53
class
unordered_object_pool:
protected
pool<UserAllocator>
54
{
55
public
:
56
typedef
T
element_type
;
57
typedef
UserAllocator
user_allocator
;
58
typedef
typename
pool<UserAllocator>::size_type
size_type
;
59
typedef
typename
pool<UserAllocator>::difference_type
difference_type
;
60
61
protected
:
62
pool<UserAllocator> &
store
() {
return
*
this
; }
63
const
pool<UserAllocator> &
store
()
const
{
return
*
this
; }
64
65
// for the sake of code readability :)
66
static
void
* &
nextof
(
void
*
const
ptr)
67
{
return
*(
static_cast<
void
**
>
(ptr)); }
68
69
public
:
70
// This constructor parameter is an extension!
71
explicit
unordered_object_pool
(
const
size_type
next_size = 32)
72
:pool<UserAllocator>(sizeof(
T
), next_size) { }
73
74
~unordered_object_pool
();
75
76
// Returns 0 if out-of-memory
77
element_type
*
malloc
()
78
{
return
static_cast<
element_type
*
>
(
store
().malloc()); }
79
void
free
(
element_type
*
const
chunk)
80
{
store
().free(chunk); }
81
bool
is_from
(
element_type
*
const
chunk)
const
82
{
return
store
().is_from(chunk); }
83
84
element_type
*
construct
()
85
{
86
element_type
*
const
ret =
malloc
();
87
if
(ret == 0)
88
return
ret;
89
/*try*/
{
new
(ret)
element_type
(); }
90
/*catch (...) { free(ret); throw; }*/
91
return
ret;
92
}
93
94
// Include automatically-generated file for family of template construct()
95
// functions
96
#ifndef BOOST_NO_TEMPLATE_CV_REF_OVERLOADS
97
# include <boost/pool/detail/pool_construct.inc>
98
#else
99
# include <boost/pool/detail/pool_construct_simple.inc>
100
#endif
101
102
void
destroy
(
element_type
*
const
chunk)
103
{
104
chunk->~T();
105
free
(chunk);
106
}
107
108
// These functions are extensions!
109
size_type
get_next_size
()
const
{
return
store
().get_next_size(); }
110
void
set_next_size
(
const
size_type
x) {
store
().set_next_size(x); }
111
};
112
113
template
<
typename
T,
typename
UserAllocator>
114
unordered_object_pool<T, UserAllocator>::~unordered_object_pool
()
115
{
116
}
117
118
}
// namespace boost
119
120
// The following code might be put into some Boost.Config header in a later revision
121
#ifdef __BORLANDC__
122
# pragma option pop
123
#endif
124
125
#endif
Generated on Sat Jun 1 2013 11:32:47 for Rosetta 3.5 by
1.8.4