Pool
Pool
Pool
Stephen Cleary
Copyright © 2000-2006 Stephen Cleary
Copyright © 2011 Paul A. Bristow
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
Table of Contents
Introduction and Overview ....................................................................................................................................... 2
Documentation Naming and Formatting Conventions ............................................................................................ 2
Introduction .................................................................................................................................................. 2
How do I use Pool? ........................................................................................................................................ 3
Installation .................................................................................................................................................... 3
Building the Test Programs .............................................................................................................................. 3
Boost Pool Interfaces - What interfaces are provided and when to use each one. ......................................................... 3
Pool in More Depth ...................................................................................................................................... 10
Boost.Pool C++ Reference ..................................................................................................................................... 22
Header <boost/pool/object_pool.hpp> .............................................................................................................. 22
Header <boost/pool/pool.hpp> ........................................................................................................................ 25
Header <boost/pool/pool_alloc.hpp> ................................................................................................................ 31
Header <boost/pool/poolfwd.hpp> ................................................................................................................... 41
Header <boost/pool/simple_segregated_storage.hpp> .......................................................................................... 41
Header <boost/pool/singleton_pool.hpp> .......................................................................................................... 45
Appendices ......................................................................................................................................................... 50
Appendix A: History ..................................................................................................................................... 50
Appendix B: FAQ ......................................................................................................................................... 50
Appendix C: Acknowledgements ..................................................................................................................... 50
Appendix D: Tests ........................................................................................................................................ 50
Appendix E: Tickets ...................................................................................................................................... 50
Appendix F: Other Implementations ................................................................................................................. 51
Appendix G: References ................................................................................................................................ 51
Appendix H: Future plans .............................................................................................................................. 52
Indexes ............................................................................................................................................................... 53
• Free functions are rendered in the code font followed by (), as in free_function().
• If a name refers to a class template, it is specified like this: class_template<>; that is, it is in code font and its name is followed
by <> to indicate that it is a class template.
• If a name refers to a function-like macro, it is specified like this: MACRO(); that is, it is uppercase in code font and its name is
followed by () to indicate that it is a function-like macro. Object-like macros appear without the trailing ().
• Names that refer to concepts in the generic programming sense are specified in CamelCase.
Note
In addition, notes such as this one specify non-essential information that provides additional background or rationale.
Finally, you can mentally add the following to any code fragments in this document:
Introduction
What is Pool?
Pool allocation is a memory allocation scheme that is very fast, but limited in its usage. For more information on pool allocation
(also called simple segregated storage, see concepts concepts and Simple Segregated Storage).
Using Pools gives you more control over how memory is used in your program. For example, you could have a situation where you
want to allocate a bunch of small objects at one point, and then reach a point in your program where none of them are needed any
more. Using pool interfaces, you can choose to run their destructors or just drop them off into oblivion; the pool interface will
guarantee that there are no system memory leaks.
Pools are generally used when there is a lot of allocation and deallocation of small objects. Another common usage is the situation
above, where many objects may be dropped out of memory.
In general, use Pools when you need a more efficient way to do unusual memory control.
pool_allocator is a more general-purpose solution, geared towards efficiently servicing requests for any number of contiguous
chunks.
fast_pool_allocator is also a general-purpose solution but is geared towards efficiently servicing requests for one chunk at a
time; it will work for contiguous chunks, but not as well as pool_allocator.
If you are seriously concerned about performance, use fast_pool_allocator when dealing with containers such as std::list,
and use pool_allocator when dealing with containers such as std::vector.
Forward declarations of all the exposed symbols for this library are in the header made inscope by #include
<boost/pool/poolfwd.hpp>.
The library may use macros, which will be prefixed with BOOST_POOL_. The exception to this rule are the include file guards, which
(for file xxx.hpp) is BOOST_xxx_HPP.
All exposed symbols defined by the library will be in namespace boost::. All symbols used only by the implementation will be in
namespace boost::details::pool.
Any header in the library may include any other header in the library or any system-supplied header at its discretion.
Installation
The Boost Pool library is a header-only library. That means there is no .lib, .dll, or .so to build; just add the Boost directory to your
compiler's include file path, and you should be good to go!
Object Usage is the method where each Pool is an object that may be created and destroyed. Destroying a Pool implicitly frees all
chunks that have been allocated from it.
Singleton Usage is the method where each Pool is an object with static duration; that is, it will not be destroyed until program exit.
Pool objects with Singleton Usage may be shared; thus, Singleton Usage implies thread-safety as well. System memory allocated
by Pool objects with Singleton Usage may be freed through release_memory or purge_memory.
Some Pool interfaces throw exceptions when out-of-memory; others will return 0. In general, unless mandated by the Standard,
Pool interfaces will always prefer to return 0 instead of throwing an exception.
An ordered pool maintains it's free list in order of the address of each free block - this is the most efficient way if you're likely to
allocate arrays of objects. However, freeing an object can be O(N) in the number of currently free blocks which can be prohibitively
expensive in some situations.
An unordered pool does not maintain it's free list in any particular order, as a result allocation and freeing single objects is very fast,
but allocating arrays may be slow (and in particular the pool may not be aware that it contains enough free memory for the allocation
request, and unnecessarily allocate more memory).
Pool Interfaces
pool
The pool interface is a simple Object Usage interface with Null Return.
pool is a fast memory allocator, and guarantees proper alignment of all allocated chunks.
pool.hpp provides two UserAllocator classes and a template class pool, which extends and generalizes the framework
provided by the Simple Segregated Storage solution. For information on other pool-based interfaces, see the other Pool Interfaces.
Synopsis
There are two UserAllocator classes provided. Both of them are in pool.hpp.
The default value for the template parameter UserAllocator is always default_user_allocator_new_delete.
struct default_user_allocator_new_delete
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
struct default_user_allocator_malloc_free
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
public:
typedef UserAllocator user_allocator;
typedef typename UserAllocator::size_type size_type;
typedef typename UserAllocator::difference_type difference_type;
bool release_memory();
bool purge_memory();
void * malloc();
void * ordered_malloc();
void * ordered_malloc(size_type n);
Example:
void func()
{
boost::pool<> p(sizeof(int));
for (int i = 0; i < 10000; ++i)
{
int * const t = p.malloc();
... // Do something with t; don't take the time to free() it.
}
} // on function exit, p is destroyed, and all malloc()'ed ints are implicitly freed.
Object_pool
The template class object_pool interface is an Object Usage interface with Null Return, but is aware of the type of the object
for which it is allocating chunks. On destruction, any chunks that have been allocated from that object_pool will have their de-
structors called.
object_pool.hpp provides a template type that can be used for fast and efficient memory allocation. It also provides automatic
destruction of non-deallocated objects.
For information on other pool-based interfaces, see the other Pool Interfaces.
Synopsis
public:
typedef ElementType element_type;
typedef UserAllocator user_allocator;
typedef typename pool<UserAllocator>::size_type size_type;
typedef typename pool<UserAllocator>::difference_type difference_type;
object_pool();
~object_pool();
element_type * malloc();
void free(element_type * p);
bool is_from(element_type * p) const;
element_type * construct();
// other construct() functions
void destroy(element_type * p);
};
Template Parameters
ElementType
The template parameter is the type of object to allocate/deallocate. It must have a non-throwing destructor.
UserAllocator
Defines the method that the underlying Pool will use to allocate memory from the system. Default is default_user_allocator_new_delete.
See __UserAllocator for details.
void func()
{
boost::object_pool<X> p;
for (int i = 0; i < 10000; ++i)
{
X * const t = p.malloc();
... // Do something with t; don't take the time to free() it.
}
} // on function exit, p is destroyed, and all destructors for the X objects are called.
Singleton_pool
The singleton_pool interface at singleton_pool.hpp is a Singleton Usage interface with Null Return. It's just the same
as the pool interface but with Singleton Usage instead.
Synopsis
private:
static pool<size_type> p; // exposition only!
singleton_pool();
public:
static bool is_from(void * ptr);
Notes
The underlying pool p referenced by the static functions in singleton_pool is actually declared in a way so that it is:
• Thread-safe if there is only one thread running before main() begins and after main() ends. All of the static functions of
singleton_pool synchronize their access to p.
• Guaranteed to be constructed before it is used, so that the simple static object in the synopsis above would actually be an incorrect
implementation. The actual implementation to guarantee this is considerably more complicated.
Note that a different underlying pool p exists for each different set of template parameters, including implementation-specific ones.
Template Parameters
Tag
The Tag template parameter allows different unbounded sets of singleton pools to exist. For example, the pool allocators use two
tag classes to ensure that the two different allocator types never share the same underlying singleton pool.
RequestedSize The requested size of memory chunks to allocate. This is passed as a constructor parameter to the underlying pool.
Must be greater than 0.
UserAllocator
Defines the method that the underlying pool will use to allocate memory from the system. See User Allocators for details.
pool_allocator
The pool_allocator interface is a Singleton Usage interface with Exceptions. It is built on the singleton_pool interface, and
provides a Standard Allocator-compliant class (for use in containers, etc.).
Introduction
pool_alloc.hpp
Provides two template types that can be used for fast and efficient memory allocation. These types both satisfy the Standard Alloc-
ator requirements [20.1.5] and the additional requirements in [20.1.5/4], so they can be used with Standard or user-supplied containers.
For information on other pool-based interfaces, see the other Pool Interfaces.
Synopsis
struct pool_allocator_tag { };
template <typename T,
typename UserAllocator = default_user_allocator_new_delete>
class pool_allocator
{
public:
typedef UserAllocator user_allocator;
typedef T value_type;
typedef value_type * pointer;
typedef const value_type * const_pointer;
typedef value_type & reference;
typedef const value_type & const_reference;
typedef typename pool<UserAllocator>::size_type size_type;
typedef typename pool<UserAllcoator>::difference_type difference_type;
public:
pool_allocator();
pool_allocator(const pool_allocator &);
// The following is not explicit, mimicking std::allocator [20.4.1]
template <typename U>
pool_allocator(const pool_allocator<U, UserAllocator> &);
pool_allocator & operator=(const pool_allocator &);
~pool_allocator();
struct fast_pool_allocator_tag { };
template <typename T
typename UserAllocator = default_user_allocator_new_delete>
class fast_pool_allocator
{
public:
typedef UserAllocator user_allocator;
typedef T value_type;
typedef value_type * pointer;
typedef const value_type * const_pointer;
typedef value_type & reference;
typedef const value_type & const_reference;
typedef typename pool<UserAllocator>::size_type size_type;
typedef typename pool<UserAllocator>::difference_type difference_type;
public:
fast_pool_allocator();
fast_pool_allocator(const fast_pool_allocator &);
// The following is not explicit, mimicking std::allocator [20.4.1]
template <typename U>
fast_pool_allocator(const fast_pool_allocator<U, UserAllocator> &);
fast_pool_allocator & operator=(const fast_pool_allocator &);
~fast_pool_allocator();
Template Parameters
UserAllocator Defines the method that the underlying Pool will use to allocate memory from the system. See User Allocators for
details.
Example:
void func()
{
std::vector<int, boost::pool_allocator<int> > v;
for (int i = 0; i < 10000; ++i)
v.push_back(13);
} // Exiting the function does NOT free the system memory allocated by the pool allocator.
// You must call
// boost::singleton_pool<boost::pool_allocator_tag, sizeof(int)>::release_memory();
// in order to force freeing the system memory.
Everyone uses dynamic memory allocation. If you have ever called malloc or new, then you have used dynamic memory allocation.
Most programmers have a tendency to treat the heap as a “magic bag"”: we ask it for memory, and it magically creates some for us.
Sometimes we run into problems because the heap is not magic.
The heap is limited. Even on large systems (i.e., not embedded) with huge amounts of virtual memory available, there is a limit.
Everyone is aware of the physical limit, but there is a more subtle, 'virtual' limit, that limit at which your program (or the entire system)
slows down due to the use of virtual memory. This virtual limit is much closer to your program than the physical limit, especially
if you are running on a multitasking system. Therefore, when running on a large system, it is considered nice to make your program
10
use as few resources as necessary, and release them as soon as possible. When using an embedded system, programmers usually
have no memory to waste.
The heap is complicated. It has to satisfy any type of memory request, for any size, and do it fast. The common approaches to memory
management have to do with splitting the memory up into portions, and keeping them ordered by size in some sort of a tree or list
structure. Add in other factors, such as locality and estimating lifetime, and heaps quickly become very complicated. So complicated,
in fact, that there is no known perfect answer to the problem of how to do dynamic memory allocation. The diagrams below illustrate
how most common memory managers work: for each chunk of memory, it uses part of that memory to maintain its internal tree or
list structure. Even when a chunk is malloc'ed out to a program, the memory manager must save some information in it - usually just
its size. Then, when the block is free'd, the memory manager can easily tell how large it is.
Because of the complication of dynamic memory allocation, it is often inefficient in terms of time and/or space. Most memory alloc-
ation algorithms store some form of information with each memory block, either the block size or some relational information, such
as its position in the internal tree or list structure. It is common for such header fields to take up one machine word in a block that
is being used by the program. The obvious disadvantage, then, is when small objects are dynamically allocated. For example, if ints
were dynamically allocated, then automatically the algorithm will reserve space for the header fields as well, and we end up with a
50% waste of memory. Of course, this is a worst-case scenario. However, more modern programs are making use of small objects
on the heap; and that is making this problem more and more apparent. Wilson et. al. state that an average-case memory overhead is
about ten to twenty percent2. This memory overhead will grow higher as more programs use more smaller objects. It is this memory
overhead that brings programs closer to the virtual limit.
In larger systems, the memory overhead is not as big of a problem (compared to the amount of time it would take to work around
it), and thus is often ignored. However, there are situations where many allocations and/or deallocations of smaller objects are taking
place as part of a time-critical algorithm, and in these situations, the system-supplied memory allocator is often too slow.
Simple segregated storage addresses both of these issues. Almost all memory overhead is done away with, and all allocations can
take place in a small amount of (amortized) constant time. However, this is done at the loss of generality; simple segregated storage
only can allocate memory chunks of a single size.
11
Each of the chunks in any given block are always the same size. This is the fundamental restriction of Simple Segregated Storage:
you cannot ask for chunks of different sizes. For example, you cannot ask a Pool of integers for a character, or a Pool of characters
for an integer (assuming that characters and integers are different sizes).
Simple Segregated Storage works by interleaving a free list within the unused chunks. For example:
By interleaving the free list inside the chunks, each Simple Segregated Storage only has the overhead of a single pointer (the pointer
to the first element in the list). It has no memory overhead for chunks that are in use by the process.
Simple Segregated Storage is also extremely fast. In the simplest case, memory allocation is merely removing the first chunk from
the free list, a O(1) operation. In the case where the free list is empty, another block may have to be acquired and partitioned, which
would result in an amortized O(1) time. Memory deallocation may be as simple as adding that chunk to the front of the free list, a
O(1) operation. However, more complicated uses of Simple Segregated Storage may require a sorted free list, which makes dealloc-
ation O(N).
12
Simple Segregated Storage gives faster execution and less memory overhead than a system-supplied allocator, but at the loss of
generality. A good place to use a Pool is in situations where many (noncontiguous) small objects may be allocated on the heap, or
if allocation and deallocation of the same-sized objects happens repeatedly.
Overview
Each Pool has a single free list that can extend over a number of memory blocks. Thus, Pool also has a linked list of allocated memory
blocks. Each memory block, by default, is allocated using new[], and all memory blocks are freed on destruction. It is the use of
new[] that allows us to guarantee alignment.
[5.3.3/2] (Expressions::Unary expressions::Sizeof) ... When applied to an array, the result is the total number of bytes in the array.
This implies that the size of an array of n elements is n times the size of an element.
Therefore, arrays cannot contain padding, though the elements within the arrays may contain padding.
Predicate 2: Any block of memory allocated as an array of characters through operator new[] (hereafter referred
to as the block) is properly aligned for any object of that size or smaller
• [3.7.3.1/2] (Basic concepts::Storage duration::Dynamic storage duration::Allocation functions) "... The pointer returned shall be
suitably aligned so that it can be converted to a pointer of any complete object type and then used to access the object or array
in the storage allocated ..."
• [5.3.4/10] (Expressions::Unary expressions::New) "... For arrays of char and unsigned char, the difference between the result of
the new-expression and the address returned by the allocation function shall be an integral multiple of the most stringent alignment
13
requirement (3.9) of any object type whose size is no greater than the size of the array being created. [Note: Because allocation
functions are assumed to return pointers to storage that is appropriately aligned for objects of any type, this constraint on array
allocation overhead permits the common idiom of allocating character arrays into which objects of other types will later be
placed."
Consider: imaginary object type Element of a size which is a multiple of some actual object size; assume
sizeof(Element) > POD_size
Note that an object of that size can exist. One object of that size is an array of the "actual" objects.
Note that the block is properly aligned for an Element. This directly follows from Predicate 2.
[3.9/9] (Basic concepts::Types) "An object type is a (possibly cv-qualified) type that is not a function type, not a reference type, and
not a void type."
Corollary 2: For any pointer p and integer i, if p is properly aligned for the type it points to, then p + i (when
well-defined) is properly aligned for that type; in other words, if an array is properly aligned, then each element
in that array is properly aligned
There are no quotes from the Standard to directly support this argument, but it fits the common conception of the meaning of
"alignment".
Note that the conditions for p + i being well-defined are outlined in [5.7/5]. We do not quote that here, but only make note that it
is well-defined if p and p + i both point into or one past the same array.
Let: sizeof(Element) be the least common multiple of sizes of several actual objects (T1, T2, T3, ...)
Let: block be a pointer to the memory block, pe be (Element *) block, and pn be (Tn *) block
Corollary 3: For each integer i, such that pe + i is well-defined, then for each n, there exists some integer jn
such that pn + jn is well-defined and refers to the same memory address as pe + i
This follows naturally, since the memory block is an array of Elements, and for each n, sizeof(Element) % sizeof(Tn) ==
0; thus, the boundary of each element in the array of Elements is also a boundary of each element in each array of Tn.
Theorem: For each integer i, such that pe + i is well-defined, that address (pe + i) is properly aligned for each
type Tn
Since pe + i is well-defined, then by Corollary 3, pn + jn is well-defined. It is properly aligned from Predicate 2 and Corollaries
1 and 2.
• The requested object size (requested_size); this is the size of chunks requested by the user
• void* (pointer to void); this is because we interleave our free list through the chunks
• size_type; this is because we store the size of the next block within each memory block
Each block also contains a pointer to the next block; but that is stored as a pointer to void and cast when necessary, to simplify
alignment requirements to the three types above.
14
Therefore, alloc_size is defined to be the largest of the sizes above, rounded up to be a multiple of all three sizes. This guarantees
alignment provided all alignments are powers of two: something that appears to be true on all known platforms.
Each of these sections may contain padding as necessary to guarantee alignment for each of the next sections. The size of the first
section is number_of_chunks * lcm(requested_size, sizeof(void *), sizeof(size_type)); the size of the second
section is lcm(sizeof(void *), sizeof(size_type); and the size of the third section is sizeof(size_type).
To show a visual example of possible padding, here's an example memory block where requested_size == 8 and sizeof(void
*) == sizeof(size_type) == 4
Using array arguments similar to the above, we can translate any request for contiguous memory for n objects of requested_size
into a request for m contiguous chunks. m is simply ceil(n * requested_size / alloc_size), where alloc_size is the
actual size of the chunks.
To illustrate:
15
Then, when the user deallocates the contiguous memory, we can split it up into chunks again.
Note that the implementation provided for allocating contiguous chunks uses a linear instead of quadratic algorithm. This means
that it may not find contiguous free chunks if the free list is not ordered. Thus, it is recommended to always use an ordered free list
when dealing with contiguous allocation of chunks. (In the example above, if Chunk 1 pointed to Chunk 3 pointed to Chunk 2
pointed to Chunk 4, instead of being in order, the contiguous allocation algorithm would have failed to find any of the contiguous
chunks).
Simple Segregated Storage (Not for the faint of heart - Embedded programmers
only!)
Introduction
simple_segregated_storage.hpp provides a template class simple_segregated_storage that controls access to a free list of
memory chunks.
Note that this is a very simple class, with unchecked preconditions on almost all its functions. It is intended to be the fastest and
smallest possible quick memory allocator for example, something to use in embedded systems. This class delegates many difficult
preconditions to the user (especially alignment issues). For more general usage, see the other Pool Interfaces.
16
Synopsis
public:
typedef SizeType size_type;
simple_segregated_storage();
~simple_segregated_storage();
void * malloc();
void free(void * chunk);
void ordered_free(void * chunk);
void * malloc_n(size_type n, size_type partition_sz);
void free_n(void * chunks, size_type n,
size_type partition_sz);
void ordered_free_n(void * chunks, size_type n,
size_type partition_sz);
};
Semantics
An object of type simple_segregated_storage<SizeType> is empty if its free list is empty. If it is not empty, then it is ordered
if its free list is ordered. A free list is ordered if repeated calls to malloc() will result in a constantly-increasing sequence of values,
as determined by std::less<void *>. A member function is order-preserving if the free-list maintains its order orientation (that
is, an ordered free list is still ordered after the member function call).
Symbol Meaning
Store simple_segregated_storage<SizeType>
17
Table 3. Typedefs
Symbol Type
size_type SizeType
18
Table 5. Segregation
19
20
t.ordered_free_n(chunk, void same as above same as above t.add_ordered_block(chunk, Same as above, ex-
n, partition_sz) n * partition_sz, cept it merges in
partition_sz) the free list. Order-
preserving. O(N +
n) where N is the
size of the free list.
In the following table, UserAllocator is a User Allocator type, block is a value of type char *, and n is a value of type UserAllocat-
or::size_type
There are two UserAllocator classes provided in this library: default_user_allocator_new_delete and default_user_al-
locator_malloc_free, both in pool.hpp. The default value for the template parameter UserAllocator is always default_user_al-
locator_new_delete.
21
namespace boost {
template<typename T, typename UserAllocator> class object_pool;
}
Synopsis
// In header: <boost/pool/object_pool.hpp>
// construct/copy/destruct
explicit object_pool(const size_type = 32, const size_type = 0);
~object_pool();
Description
T The type of object to allocate/deallocate. T must have a non-throwing destructor.
22
UserAllocator Defines the allocator that the underlying Pool will use to allocate memory from the system. See User Allocators for
details.
Class object_pool is a template class that can be used for fast and efficient memory allocation of objects. It also provides automatic
destruction of non-deallocated objects.
When the object pool is destroyed, then the destructor for type T is called for each allocated T that has not yet been deallocated.
O(N).
Whenever an object of type ObjectPool needs memory from the system, it will request it from its UserAllocator template parameter.
The amount requested is determined using a doubling algorithm; that is, each time more system memory is allocated, the amount of
system memory requested is doubled. Users may control the doubling algorithm by the parameters passed to the object_pool's con-
structor.
1.
explicit object_pool(const size_type arg_next_size = 32,
const size_type arg_max_size = 0);
2.
~object_pool();
1.
pool< UserAllocator > & store();
2.
const pool< UserAllocator > & store() const;
1.
static void *& nextof(void *const ptr);
Returns: The next memory block after ptr (for the sake of code readability :)
1.
element_type * malloc();
Amortized O(1).
2.
void free(element_type *const chunk);
23
3.
bool is_from(element_type *const chunk) const;
Returns false if chunk was allocated from some other pool or may be returned as the result of a future allocation from some other
pool.
Note
This function may NOT be used to reliably test random pointer values!
Returns: true if chunk was allocated from *this or may be returned as the result of a future allocation from *this.
4.
element_type * construct();
Returns: A pointer to an object of type T, allocated in memory from the underlying pool and default constructed. The returned
objected can be freed by a call to destroy. Otherwise the returned object will be automatically destroyed when *this
is destroyed.
5.
template<typename Arg1, ...class ArgN>
element_type * construct(Arg1 &, ...ArgN &);
Note
Since the number and type of arguments to this function is totally arbitrary, a simple system has been set up to
automatically generate template construct functions. This system is based on the macro preprocessor m4, which
is standard on UNIX systems and also available for Win32 systems.
detail/pool_construct.m4, when run with m4, will create the file detail/pool_construct.ipp, which only defines
the construct functions for the proper number of arguments. The number of arguments may be passed into the
file as an m4 macro, NumberOfArguments; if not provided, it will default to 3.
For each different number of arguments (1 to NumberOfArguments), a template function is generated. There are
the same number of template parameters as there are arguments, and each argument's type is a reference to that
(possibly cv-qualified) template argument. Each possible permutation of the cv-qualifications is also generated.
Because each permutation is generated for each possible number of arguments, the included file size grows ex-
ponentially in terms of the number of constructor arguments, not linearly. For the sake of rational compile times,
only use as many arguments as you need.
detail/pool_construct.bat and detail/pool_construct.sh are also provided to call m4, defining NumberOfArguments
to be their command-line parameter. See these files for more details.
Returns: A pointer to an object of type T, allocated in memory from the underlying pool and constructed from arguments
Arg1 to ArgN. The returned objected can be freed by a call to destroy. Otherwise the returned object will be auto-
matically destroyed when *this is destroyed.
6.
void destroy(element_type *const chunk);
Equivalent to:
p->~ElementType(); this->free(p);
24
Requires: p must have been previously allocated from *this via a call to construct.
7.
size_type get_next_size() const;
Returns: The number of chunks that will be allocated next time we run out of memory.
8.
void set_next_size(const size_type x);
Set a new number of chunks to allocate the next time we run out of memory.
Parameters: x wanted next_size (must not be zero).
Header <boost/pool/pool.hpp>
Provides class pool: a fast memory allocator that guarantees proper alignment of all allocated chunks, and which extends and gener-
alizes the framework provided by the simple segregated storage solution. Also provides two UserAllocator classes which can be
used in conjuction with pool.
namespace boost {
struct default_user_allocator_new_delete;
struct default_user_allocator_malloc_free;
Struct default_user_allocator_new_delete
boost::default_user_allocator_new_delete — Allocator used as the default template parameter for a UserAllocator template parameter.
Uses new and delete.
Synopsis
// In header: <boost/pool/pool.hpp>
struct default_user_allocator_new_delete {
// types
typedef std::size_t size_type; // An unsigned integral type that can represent the ↵
size of the largest object to be allocated.
typedef std::ptrdiff_t difference_type; // A signed integral type that can represent the dif↵
ference of any two pointers.
Description
default_user_allocator_new_delete public static functions
1.
static char * malloc(const size_type bytes);
25
2.
static void free(char *const block);
Struct default_user_allocator_malloc_free
boost::default_user_allocator_malloc_free — UserAllocator used as template parameter for pool and object_pool. Uses malloc and
free internally.
Synopsis
// In header: <boost/pool/pool.hpp>
struct default_user_allocator_malloc_free {
// types
typedef std::size_t size_type; // An unsigned integral type that can represent the ↵
size of the largest object to be allocated.
typedef std::ptrdiff_t difference_type; // A signed integral type that can represent the dif↵
ference of any two pointers.
Description
default_user_allocator_malloc_free public static functions
1.
static char * malloc(const size_type bytes);
2.
static void free(char *const block);
26
Synopsis
// In header: <boost/pool/pool.hpp>
template<typename UserAllocator>
class pool :
protected boost::simple_segregated_storage< UserAllocator::size_type >
{
public:
// types
typedef UserAllocator user_allocator; // User allocator.
typedef UserAllocator::size_type size_type; // An unsigned integral type that ↵
can represent the size of the largest object to be allocated.
typedef UserAllocator::difference_type difference_type; // A signed integral type that can ↵
represent the difference of any two pointers.
// construct/copy/destruct
explicit pool(const size_type, const size_type = 32, const size_type = 0);
~pool();
Description
Whenever an object of type pool needs memory from the system, it will request it from its UserAllocator template parameter. The
amount requested is determined using a doubling algorithm; that is, each time more system memory is allocated, the amount of
system memory requested is doubled.
Users may control the doubling algorithm by using the following extensions:
Users may pass an additional constructor parameter to pool. This parameter is of type size_type, and is the number of chunks to request
from the system the first time that object needs to allocate system memory. The default is 32. This parameter may not be 0.
27
Users may also pass an optional third parameter to pool's constructor. This parameter is of type size_type, and sets a maximum size
for allocated chunks. When this parameter takes the default value of 0, then there is no upper limit on chunk size.
Finally, if the doubling algorithm results in no memory being allocated, the pool will backtrack just once, halving the chunk size
and trying again.
UserAllocator type - the method that the Pool will use to allocate memory from the system.
There are essentially two ways to use class pool: the client can call malloc() and free() to allocate and free single chunks of memory,
this is the most efficient way to use a pool, but does not allow for the efficient allocation of arrays of chunks. Alternatively, the client
may call ordered_malloc() and ordered_free(), in which case the free list is maintained in an ordered state, and efficient allocation
of arrays of chunks are possible. However, this latter option can suffer from poor performance when large numbers of allocations
are performed.
1.
explicit pool(const size_type nrequested_size,
const size_type nnext_size = 32, const size_type nmax_size = 0);
Constructs a new empty Pool that can be used to allocate chunks of size RequestedSize.
Parameters: nmax_size is the maximum number of chunks to allocate in one block.
nnext_size parameter is of type size_type, is the number of chunks to request from the system
the first time that object needs to allocate system memory. The default is 32. This
parameter may not be 0.
nrequested_size Requested chunk size
2.
~pool();
1.
void * malloc_need_resize();
No memory in any of our storages; make a new storage, Allocates chunk in newly malloc aftert resize.
Returns: 0 if out-of-memory. Called if malloc/ordered_malloc needs to resize the free list.
Returns: pointer to chunk.
2.
void * ordered_malloc_need_resize();
1.
simple_segregated_storage< size_type > & store();
2.
const simple_segregated_storage< size_type > & store() const;
28
3.
details::PODptr< size_type > find_POD(void *const chunk) const;
4.
size_type alloc_size() const;
Calculated size of the memory chunks that will be allocated by this Pool.
Returns: allocated size.
1.
static bool is_from(void *const chunk, char *const i,
const size_type sizeof_i);
Returns false if chunk was allocated from some other pool, or may be returned as the result of a future allocation from some
other pool. Otherwise, the return value is meaningless.
Note that this function may not be used to reliably test random pointer values.
Parameters: chunk chunk to check if is from this pool.
i memory chunk at i with element sizeof_i.
sizeof_i element size (size of the chunk area of that block, not the total size of that block).
Returns: true if chunk was allocated or may be returned. as the result of a future allocation.
2.
static void *& nextof(void *const ptr);
Returns: Pointer dereferenced. (Provided and used for the sake of code readability :)
1.
bool release_memory();
pool must be ordered. Frees every memory block that doesn't have any allocated chunks.
Returns: true if at least one memory block was freed.
2.
bool purge_memory();
3.
size_type get_next_size() const;
Number of chunks to request from the system the next time that object needs to allocate system memory. This value should never
be 0.
Returns: next_size;
4.
void set_next_size(const size_type nnext_size);
Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should
never be set to 0.
29
Returns: nnext_size.
5.
size_type get_max_size() const;
Returns: max_size.
6.
void set_max_size(const size_type nmax_size);
Set max_size.
7.
size_type get_requested_size() const;
Returns: the requested size passed into the constructor. (This value will not change during the lifetime of a Pool object).
8.
void * malloc();
Allocates a chunk of memory. Searches in the list of memory blocks for a block that has a free chunk, and returns that free chunk
if found. Otherwise, creates a new memory block, adds its free list to pool's free list,
Returns: a free chunk from that block. If a new memory block cannot be allocated, returns 0. Amortized O(1).
9.
void * ordered_malloc();
Same as malloc, only merges the free lists, to preserve order. Amortized O(1).
Returns: a free chunk from that block. If a new memory block cannot be allocated, returns 0. Amortized O(1).
10.
void * ordered_malloc(size_type n);
11.
void free(void *const chunk);
Same as malloc, only allocates enough contiguous chunks to cover n * requested_size bytes. Amortized O(n).
Chunk must have been previously returned by t.malloc() or t.ordered_malloc(). Assumes that chunk actually refers to a block of
chunks spanning n * partition_sz bytes. deallocates each chunk in that block. Note that chunk may not be 0. O(n).
Returns: a free chunk from that block. If a new memory block cannot be allocated, returns 0. Amortized O(1).
12.
void ordered_free(void *const chunk);
Note that chunk may not be 0. O(N) with respect to the size of the free list. chunk must have been previously returned by t.malloc()
or t.ordered_malloc().
13.
void free(void *const chunks, const size_type n);
30
chunk must have been previously returned by t.ordered_malloc(n) spanning n * partition_sz bytes. Deallocates each chunk in that
block. Note that chunk may not be 0. O(n).
14.
void ordered_free(void *const chunks, const size_type n);
Assumes that chunk actually refers to a block of chunks spanning n * partition_sz bytes; deallocates each chunk in that block.
Note that chunk may not be 0. Order-preserving. O(N + n) where N is the size of the free list. chunk must have been previously
returned by t.malloc() or t.ordered_malloc().
15.
bool is_from(void *const chunk) const;
Returns: Returns true if chunk was allocated from u or may be returned as the result of a future allocation from u. Returns
false if chunk was allocated from some other pool or may be returned as the result of a future allocation from some
other pool. Otherwise, the return value is meaningless. Note that this function may not be used to reliably test random
pointer values.
Header <boost/pool/pool_alloc.hpp>
C++ Standard Library compatible pool-based allocators.
This header provides two template types - pool_allocator and fast_pool_allocator - that can be used for fast and efficient memory
allocation in conjunction with the C++ Standard Library containers.
These types both satisfy the Standard Allocator requirements [20.1.5] and the additional requirements in [20.1.5/4], so they can be
used with either Standard or user-supplied containers.
In addition, the fast_pool_allocator also provides an additional allocation and an additional deallocation function:
PoolAlloc::allocate() T * PoolAlloc::allocate(1)
The typedef user_allocator publishes the value of the UserAllocator template parameter.
Notes
If the allocation functions run out of memory, they will throw std::bad_alloc.
The underlying Pool type used by the allocators is accessible through the Singleton Pool Interface. The identifying tag used for
pool_allocator is pool_allocator_tag, and the tag used for fast_pool_allocator is fast_pool_allocator_tag. All template parameters of
the allocators (including implementation-specific ones) determine the type of the underlying Pool, with the exception of the first
parameter T, whose size is used instead.
Since the size of T is used to determine the type of the underlying Pool, each allocator for different types of the same size will share
the same underlying pool. The tag class prevents pools from being shared between pool_allocator and fast_pool_allocator. For example,
on a system where sizeof(int) == sizeof(void *), pool_allocator<int> and pool_allocator<void *> will both
allocate/deallocate from/to the same pool.
If there is only one thread running before main() starts and after main() ends, then both allocators are completely thread-safe.
31
A number of common STL libraries contain bugs in their using of allocators. Specifically, they pass null pointers to the deallocate
function, which is explicitly forbidden by the Standard [20.1.5 Table 32]. PoolAlloc will work around these libraries if it detects
them; currently, workarounds are in place for: Borland C++ (Builder and command-line compiler) with default (RogueWave) library,
ver. 5 and earlier, STLport (with any compiler), ver. 4.0 and earlier.
namespace boost {
struct pool_allocator_tag;
struct fast_pool_allocator_tag;
Struct pool_allocator_tag
boost::pool_allocator_tag
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
struct pool_allocator_tag {
};
Description
Simple tag type used by pool_allocator as an argument to the underlying singleton_pool.
32
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
// member classes/structs/unions
// construct/copy/destruct
pool_allocator();
template<typename U>
pool_allocator(const pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &);
Description
Template parameters for pool_allocator are defined as follows:
33
UserAllocator. Defines the method that the underlying Pool will use to allocate memory from the system. See User Allocators for
details.
Mutex Allows the user to determine the type of synchronization to be used on the underlying singleton_pool.
NextSize The value of this parameter is passed to the underlying singleton_pool when it is created.
Note
The underlying singleton_pool used by the this allocator constructs a pool instance that is never freed. This means
that memory allocated by the allocator can be still used after main() has completed, but may mean that some memory
checking programs will complain about leaks.
1.
pool_allocator();
Results in default construction of the underlying singleton_pool IFF an instance of this allocator is constructed during global
initialization ( required to ensure construction of singleton_pool IFF an instance of this allocator is constructed during global
initialization. See ticket #2359 for a complete explanation at http://svn.boost.org/trac/boost/ticket/2359) .
2.
template<typename U>
pool_allocator(const pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &);
Results in the default construction of the underlying singleton_pool, this is required to ensure construction of singleton_pool
IFF an instance of this allocator is constructed during global initialization. See ticket #2359 for a complete explanation at ht-
tp://svn.boost.org/trac/boost/ticket/2359 .
1.
bool operator==(const pool_allocator &) const;
2.
bool operator!=(const pool_allocator &) const;
1.
static pointer address(reference r);
2.
static const_pointer address(const_reference s);
3.
static size_type max_size();
4.
static void construct(const pointer ptr, const value_type & t);
34
5.
static void destroy(const pointer ptr);
6.
static pointer allocate(const size_type n);
7.
static pointer allocate(const size_type n, const void * const);
allocate n bytes
8.
static void deallocate(const pointer ptr, const size_type n);
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
Description
Nested class rebind allows for transformation from pool_allocator<T> to pool_allocator<U> via the member typedef other.
Specializations
35
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
// member classes/structs/unions
Description
Specialization of pool_allocator for type void: required by the standard to make this a conforming allocator type.
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
Description
Nested class rebind allows for transformation from pool_allocator<T> to pool_allocator<U> via the member typedef other.
Struct fast_pool_allocator_tag
boost::fast_pool_allocator_tag — Simple tag type used by fast_pool_allocator as a template parameter to the underlying singleton_pool.
36
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
struct fast_pool_allocator_tag {
};
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
// member classes/structs/unions
// construct/copy/destruct
fast_pool_allocator();
template<typename U>
fast_pool_allocator(const fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &);
37
Description
While class template pool_allocator is a more general-purpose solution geared towards efficiently servicing requests for any
number of contiguous chunks, fast_pool_allocator is also a general-purpose solution, but is geared towards efficiently servicing
requests for one chunk at a time; it will work for contiguous chunks, but not as well as pool_allocator.
If you are seriously concerned about performance, use fast_pool_allocator when dealing with containers such as std::list,
and use pool_allocator when dealing with containers such as std::vector.
UserAllocator. Defines the method that the underlying Pool will use to allocate memory from the system. See User Allocators for
details.
Mutex Allows the user to determine the type of synchronization to be used on the underlying singleton_pool.
NextSize The value of this parameter is passed to the underlying Pool when it is created.
Note
The underlying singleton_pool used by the this allocator constructs a pool instance that is never freed. This means
that memory allocated by the allocator can be still used after main() has completed, but may mean that some memory
checking programs will complain about leaks.
1.
fast_pool_allocator();
Ensures construction of the underlying singleton_pool IFF an instance of this allocator is constructed during global initializ-
ation. See ticket #2359 for a complete explanation at http://svn.boost.org/trac/boost/ticket/2359 .
2.
template<typename U>
fast_pool_allocator(const fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize
> &);
Ensures construction of the underlying singleton_pool IFF an instance of this allocator is constructed during global initializ-
ation. See ticket #2359 for a complete explanation at http://svn.boost.org/trac/boost/ticket/2359 .
1.
void construct(const pointer ptr, const value_type & t);
2.
void destroy(const pointer ptr);
38
3.
bool operator==(const fast_pool_allocator &) const;
4.
bool operator!=(const fast_pool_allocator &) const;
1.
static pointer address(reference r);
2.
static const_pointer address(const_reference s);
3.
static size_type max_size();
4.
static pointer allocate(const size_type n);
5.
static pointer allocate(const size_type n, const void * const);
Allocate memory .
6.
static pointer allocate();
Allocate memory.
7.
static void deallocate(const pointer ptr, const size_type n);
Deallocate memory.
8.
static void deallocate(const pointer ptr);
deallocate/free
39
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
Description
Nested class rebind allows for transformation from fast_pool_allocator<T> to fast_pool_allocator<U> via the member typedef other.
Specializations
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
// member classes/structs/unions
Description
Specialization of fast_pool_allocator<void> required to make the allocator standard-conforming.
40
Synopsis
// In header: <boost/pool/pool_alloc.hpp>
Description
Nested class rebind allows for transformation from fast_pool_allocator<T> to fast_pool_allocator<U> via the member typedef other.
Header <boost/pool/poolfwd.hpp>
Forward declarations of all public (non-implemention) classes.
Header <boost/pool/simple_segregated_storage.hpp>
Simple Segregated Storage.
A simple segregated storage implementation: simple segregated storage is the basic idea behind the Boost Pool library. Simple se-
gregated storage is the simplest, and probably the fastest, memory allocation/deallocation algorithm. It begins by partitioning a
memory block into fixed-size chunks. Where the block comes from is not important until implementation time. A Pool is some object
that uses Simple Segregated Storage in this fashion.
BOOST_POOL_VALIDATE_INTERNALS
namespace boost {
template<typename SizeType> class simple_segregated_storage;
}
41
Synopsis
// In header: <boost/pool/simple_segregated_storage.hpp>
template<typename SizeType>
class simple_segregated_storage {
public:
// types
typedef SizeType size_type;
// construct/copy/destruct
simple_segregated_storage(const simple_segregated_storage &);
simple_segregated_storage();
simple_segregated_storage& operator=(const simple_segregated_storage &);
Description
Template class simple_segregated_storage controls access to a free list of memory chunks. Please note that this is a very simple
class, with preconditions on almost all its functions. It is intended to be the fastest and smallest possible quick memory allocator -
e.g., something to use in embedded systems. This class delegates many difficult preconditions to the user (i.e., alignment issues).
An object of type simple_segregated_storage<SizeType> is empty if its free list is empty. If it is not empty, then it is ordered if its
free list is ordered. A free list is ordered if repeated calls to malloc() will result in a constantly-increasing sequence of values, as
determined by std::less<void *>. A member function is order-preserving if the free list maintains its order orientation (that is,
an ordered free list is still ordered after the member function call).
1.
simple_segregated_storage(const simple_segregated_storage &);
2.
simple_segregated_storage();
42
3.
simple_segregated_storage& operator=(const simple_segregated_storage &);
1.
static void *
try_malloc_n(void *& start, size_type n, size_type partition_size);
1.
void * find_prev(void * ptr);
Traverses the free list referred to by "first", and returns the iterator previous to where "ptr" would go if it was in the free list. Returns
0 if "ptr" would go at the beginning of the free list (i.e., before "first").
Note
Note that this function finds the location previous to where ptr would go if it was in the free list. It does not find
the entry in the free list before ptr (unless ptr is already in the free list). Specifically, find_prev(0) will return 0,
not the last entry in the free list.
Returns: location previous to where ptr would go if it was in the free list.
1.
static void *& nextof(void *const ptr);
The return value is just *ptr cast to the appropriate type. ptr must not be 0. (For the sake of code readability :)
As an example, let us assume that we want to truncate the free list after the first chunk. That is, we want to set *first to 0; this
will result in a free list with only one entry. The normal way to do this is to first cast first to a pointer to a pointer to void, and
then dereference and assign (*static_cast<void **>(first) = 0;). This can be done more easily through the use of this convenience
function (nextof(first) = 0;).
Returns: dereferenced pointer.
1.
void add_block(void *const block, const size_type nsz,
const size_type npartition_sz);
Add block Segregate this block and merge its free list into the free list referred to by "first".
Requires: Same as segregate.
Postconditions: !empty()
43
2.
void add_ordered_block(void *const block, const size_type nsz,
const size_type npartition_sz);
add block (ordered into list) This (slower) version of add_block segregates the block and merges its free list into our free list in
the proper order.
3.
bool empty() const;
4.
void * malloc();
Create a chunk.
Requires: !empty() Increment the "first" pointer to point to the next chunk.
5.
void free(void *const chunk);
Free a chunk.
Requires: chunk was previously returned from a malloc() referring to the same free list.
Postconditions: !empty()
6.
void ordered_free(void *const chunk);
This (slower) implementation of 'free' places the memory back in the list in its proper order.
Requires: chunk was previously returned from a malloc() referring to the same free list
Postconditions: !empty().
7.
void * malloc_n(size_type n, size_type partition_size);
Attempts to find a contiguous sequence of n partition_sz-sized chunks. If found, removes them all from the free list and returns
a pointer to the first. If not found, returns 0. It is strongly recommended (but not required) that the free list be ordered, as this al-
gorithm will fail to find a contiguous sequence unless it is contiguous in the free list as well. Order-preserving. O(N) with respect
to the size of the free list.
8.
void free_n(void *const chunks, const size_type n,
const size_type partition_size);
Note
If you're allocating/deallocating n a lot, you should be using an ordered pool.
Requires: chunks was previously allocated from *this with the same values for n and partition_size.
Postconditions: !empty()
9.
void ordered_free_n(void *const chunks, const size_type n,
const size_type partition_size);
44
1.
static void *
segregate(void * block, size_type nsz, size_type npartition_sz,
void * end = 0);
Block is properly aligned for an array of object of size npartition_sz and array of void *. The requirements above
guarantee that any pointer to a chunk (which is a pointer to an element in an array of npartition_sz) may be cast
to void **.
Macro BOOST_POOL_VALIDATE_INTERNALS
BOOST_POOL_VALIDATE_INTERNALS
Synopsis
// In header: <boost/pool/simple_segregated_storage.hpp>
BOOST_POOL_VALIDATE_INTERNALS
Header <boost/pool/singleton_pool.hpp>
The singleton_pool class allows other pool interfaces for types of the same size to share the same underlying pool.
Header singleton_pool.hpp provides a template class singleton_pool, which provides access to a pool as a singleton object.
namespace boost {
template<typename Tag, unsigned RequestedSize, typename UserAllocator,
typename Mutex, unsigned NextSize, unsigned MaxSize>
class singleton_pool;
}
45
Synopsis
// In header: <boost/pool/singleton_pool.hpp>
// member classes/structs/unions
struct object_creator {
// construct/copy/destruct
object_creator();
// construct/copy/destruct
singleton_pool();
Description
The singleton_pool class allows other pool interfaces for types of the same size to share the same pool. Template parameters are as
follows:
Tag User-specified type to uniquely identify this pool: allows different unbounded sets of singleton pools to exist.
46
Mutex This class is the type of mutex to use to protect simultaneous access to the underlying Pool. Can be any Boost.Thread Mutex
type or boost::details::pool::null_mutex. It is exposed so that users may declare some singleton pools normally (i.e., with
synchronization), but some singleton pools without synchronization (by specifying boost::details::pool::null_mutex) for
efficiency reasons. The member typedef mutex exposes the value of this template parameter. The default for this parameter is
boost::details::pool::default_mutex which is a synonym for either boost::details::pool::null_mutex (when threading support
is turned off in the compiler (so BOOST_HAS_THREADS is not set), or threading support has ben explicitly disabled with
BOOST_DISABLE_THREADS (Boost-wide disabling of threads) or BOOST_POOL_NO_MT (this library only)) or for
boost::mutex (when threading support is enabled in the compiler).
NextSize The value of this parameter is passed to the underlying Pool when it is created and specifies the number of chunks to allocate
in the first allocation request (defaults to 32). The member typedef static const value next_size exposes the value of this
template parameter.
MaxSizeThe value of this parameter is passed to the underlying Pool when it is created and specifies the maximum number of chunks
to allocate in any single allocation request (defaults to 0).
Notes:
The underlying pool p referenced by the static functions in singleton_pool is actually declared in a way that is:
1 Thread-safe if there is only one thread running before main() begins and after main() ends -- all of the static functions of
singleton_pool synchronize their access to p.
2 Guaranteed to be constructed before it is used -- thus, the simple static object in the synopsis above would actually be an incorrect
implementation. The actual implementation to guarantee this is considerably more complicated.
3 Note too that a different underlying pool p exists for each different set of template parameters, including implementation-specific
ones.
Note
The underlying pool constructed by the singleton is never freed. This means that memory allocated by a
singleton_pool can be still used after main() has completed, but may mean that some memory checking programs
will complain about leaks from singleton_pool.
The Tag template parameter uniquely identifies this pool and allows different unbounded sets of singleton pools to exist. For ex-
ample, the pool allocators use two tag classes to ensure that the two different allocator types never share the same underlying
singleton pool. Tag is never actually used by singleton_pool.
1.
singleton_pool();
1.
static void * malloc();
47
2.
static void * ordered_malloc();
3.
static void * ordered_malloc(const size_type n);
4.
static bool is_from(void *const ptr);
5.
static void free(void *const ptr);
6.
static void ordered_free(void *const ptr);
7.
static void free(void *const ptr, const size_type n);
8.
static void ordered_free(void *const ptr, const size_type n);
9.
static bool release_memory();
10.
static bool purge_memory();
1.
static pool_type & get_pool();
Struct object_creator
boost::singleton_pool::object_creator
48
Synopsis
// In header: <boost/pool/singleton_pool.hpp>
struct object_creator {
// construct/copy/destruct
object_creator();
Description
object_creator public construct/copy/destruct
1.
object_creator();
1.
void do_nothing() const;
49
Appendices
Appendix A: History
Version 2.0.0, January 11, 2011
Documentation and testing revision
Features:
• Documentation converted and rewritten and revised by Paul A. Bristow using Quickbook, Doxygen, for html and pdf, based on
Stephen Cleary's html version, Revised 05 December, 2006.
This used Opera 11.0, and html_to_quickbook.css as a special display format. On the Opera full taskbar (chose enable full
taskbar) View, Style, Manage modes, Display.
Appendix B: FAQ
Why should I use Pool?
Using Pools gives you more control over how memory is used in your program. For example, you could have a situation where you
want to allocate a bunch of small objects at one point, and then reach a point in your program where none of them are needed any
more. Using pool interfaces, you can choose to run their destructors or just drop them off into oblivion; the pool interface will
guarantee that there are no system memory leaks.
Pools are generally used when there is a lot of allocation and deallocation of small objects. Another common usage is the situation
above, where many objects may be dropped out of memory.
In general, use Pools when you need a more efficient way to do unusual memory control.
Appendix C: Acknowledgements
Many, many thanks to the Boost peers, notably Jeff Garland, Beman Dawes, Ed Brey, Gary Powell, Peter Dimov, and Jens Maurer
for providing helpful suggestions!
Appendix D: Tests
See folder boost/libs/pool/test/.
Appendix E: Tickets
Report and view bugs and features by adding a ticket at Boost.Trac.
50
Existing open tickets for this library alone can be viewed here. Existing tickets for this library - including closed ones - can be viewed
here.
1. The C++ Programming Language, 3rd ed., by Bjarne Stroustrup, Section 19.4.2. Missing aspects:
• Not portable.
• Cannot handle allocations of arbitrary numbers of objects (this was left as an exercise).
• Not thread-safe.
2. MicroC/OS-II: The Real-Time Kernel, by Jean J. Labrosse, Chapter 7 and Appendix B.04.
• An example of the Simple Segregated Storage scheme at work in the internals of an actual OS.
• Missing aspects:
• Not portable (though this is OK, since it's part of its own OS).
• Cannot handle allocations of arbitrary numbers of blocks (which is also OK, since this feature is not needed).
3. Efficient C++: Performance Programming Techniques, by Dov Bulka and David Mayhew, Chapters 6 and 7.
• however, their premise (that the system-supplied allocation mechanism is hopelessly inefficient) is flawed on every system
I've tested on.
• Run their timings on your system before you accept their conclusions.
• Missing aspect: Requires non-intuitive user code to create and destroy the Pool.
4. Advanced C++: Programming Styles and Idioms, by James O. Coplien, Section 3.6.
• Has examples of both static and dynamic pooling, but missing aspects:
• Not thread-safe.
Appendix G: References
1. Doug Lea, A Memory Allocator. See http://gee.cs.oswego.edu/dl/html/malloc.html
2. Paul R. Wilson, Mark S. Johnstone, Michael Neely, and David Boles, Dynamic Storage Allocation: A Survey and Critical Review
in International Workshop on Memory Management, September 1995, pg. 28, 36. See ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps
51
This "pool_base" interface will be Singleton Usage with Exceptions, and built on the singleton_pool interface.
52
Indexes
Function Index
A
address
Class template fast_pool_allocator, 37, 39
Class template pool_allocator, 33, 34
Guaranteeing Alignment - How we guarantee alignment portably., 13
pool_allocator, 8
add_block
Class template simple_segregated_storage, 42, 43
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
add_ordered_block
Class template simple_segregated_storage, 42, 44
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
allocate
Class template fast_pool_allocator, 37, 39
Class template pool_allocator, 33, 35
pool_allocator, 8
C
construct
Class template fast_pool_allocator, 37, 38
Class template object_pool, 22, 24
Class template pool_allocator, 33, 34
Object_pool, 6
pool_allocator, 8
D
deallocate
Class template fast_pool_allocator, 37, 39
Class template pool_allocator, 33, 35
pool_allocator, 8
destroy
Class template fast_pool_allocator, 37, 38
Class template object_pool, 22, 24
Class template pool_allocator, 33, 35
Object_pool, 6
pool_allocator, 8
F
find_prev
Class template simple_segregated_storage, 42, 43
free
Class template object_pool, 22, 23
Class template pool, 27, 30
Class template simple_segregated_storage, 42, 44
Class template singleton_pool, 46, 48
Object_pool, 6
pool, 4
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25, 26
53
free_n
Class template simple_segregated_storage, 42, 44
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
G
get_pool
Class template singleton_pool, 46, 48
I
is_from
Class template object_pool, 22, 24
Class template pool, 27, 29, 31
Class template singleton_pool, 46, 48
Object_pool, 6
pool, 4
Singleton_pool, 7
M
main
Class template fast_pool_allocator, 38
Class template pool_allocator, 33
Class template singleton_pool, 46
Header < boost/pool/pool_alloc.hpp >, 31
Singleton_pool, 7
malloc
Class template object_pool, 22, 23
Class template pool, 27, 28, 30, 31
Class template simple_segregated_storage, 42, 44
Class template singleton_pool, 46, 47
Object_pool, 6
pool, 4
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25, 26
malloc_n
Class template simple_segregated_storage, 42, 44
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
malloc_need_resize
Class template pool, 27, 28
max_size
Class template fast_pool_allocator, 37, 39
Class template pool_allocator, 33, 34
pool_allocator, 8
N
nextof
Class template object_pool, 22, 23
Class template pool, 27, 29
Class template simple_segregated_storage, 42, 43
O
ordered_free
Class template pool, 27, 30, 31
Class template simple_segregated_storage, 42, 44
Class template singleton_pool, 46, 48
54
pool, 4
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
ordered_free_n
Class template simple_segregated_storage, 42, 44
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
ordered_malloc
Class template pool, 27, 30
Class template singleton_pool, 46, 48
pool, 4
Singleton_pool, 7
ordered_malloc_need_resize
Class template pool, 27, 28
P
purge_memory
Class template pool, 27, 29
Class template singleton_pool, 46, 48
pool, 4
Singleton_pool, 7
R
release_memory
Class template pool, 27, 29
Class template singleton_pool, 46, 48
pool, 4
Singleton_pool, 7
S
segregate
Class template simple_segregated_storage, 42, 45
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
set_max_size
Class template pool, 27, 30
set_next_size
Class template object_pool, 22, 25
Class template pool, 27, 29
sizeof
Guaranteeing Alignment - How we guarantee alignment portably., 13
Header < boost/pool/pool_alloc.hpp >, 31
How Contiguous Chunks are Handled, 15
T
try_malloc_n
Class template simple_segregated_storage, 42, 43
Class Index
D
default_user_allocator_malloc_free
pool, 4
Struct default_user_allocator_malloc_free, 26
default_user_allocator_new_delete
pool, 4
Struct default_user_allocator_new_delete, 25
55
F
fast_pool_allocator
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
pool_allocator, 8
Struct template rebind, 40, 41
fast_pool_allocator_tag
pool_allocator, 8
Struct fast_pool_allocator_tag, 37
O
object_creator
Class template singleton_pool, 46
Struct object_creator, 49
object_pool
Class template object_pool, 22, 23
Object_pool, 6
P
pool
Class template object_pool, 22
Class template pool, 27
pool, 4
pool_allocator
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
pool_allocator, 8
Struct template rebind, 35, 36
pool_allocator_tag
pool_allocator, 8
Struct pool_allocator_tag, 32
R
rebind
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
pool_allocator, 8
Struct template rebind, 35, 36, 40, 41
S
simple_segregated_storage
Class template pool, 27
Class template simple_segregated_storage, 42
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
singleton_pool
Class template singleton_pool, 45, 46, 47, 48
Singleton_pool, 7
Typedef Index
C
const_pointer
Class template fast_pool_allocator, 37
56
D
difference_type
Class template fast_pool_allocator, 37
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator, 33
Class template singleton_pool, 46
Object_pool, 6
pool, 4
pool_allocator, 8
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25
E
element_type
Class template object_pool, 22
Object_pool, 6
M
mutex
Class template fast_pool_allocator, 37
Class template pool_allocator, 33
Class template singleton_pool, 46
O
other
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
pool_allocator, 8
Struct template rebind, 35, 36, 40, 41
P
pointer
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
pool_allocator, 8
R
reference
Class template fast_pool_allocator, 37
Class template pool_allocator, 33
pool_allocator, 8
57
S
size_type
Class template fast_pool_allocator, 37
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator, 33
Class template simple_segregated_storage, 42
Class template singleton_pool, 46
Object_pool, 6
pool, 4
pool_allocator, 8
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25
T
tag
Class template singleton_pool, 46, 47
Singleton_pool, 7
U
user_allocator
Class template fast_pool_allocator, 37
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator, 33
Class template singleton_pool, 46
Object_pool, 6
pool, 4
pool_allocator, 8
Singleton_pool, 7
V
value_type
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
pool_allocator, 8
Index
A
address
Class template fast_pool_allocator, 37, 39
Class template pool_allocator, 33, 34
Guaranteeing Alignment - How we guarantee alignment portably., 13
pool_allocator, 8
add_block
Class template simple_segregated_storage, 42, 43
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
add_ordered_block
Class template simple_segregated_storage, 42, 44
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
alignment
58
59
B
Basic ideas behind pooling
allocation, 10
block, 10
chunk, 10
headers, 10
malloc, 10
memory, 10
new, 10
objects, 10
ordered, 10
segregated, 10
size, 10
block
Allocation and Deallocation, 16
Appendix F: Other Implementations, 51
Basic ideas behind pooling, 10
Boost Pool Interfaces - What interfaces are provided and when to use each one., 3
Class template object_pool, 23
Class template pool, 28, 29, 30, 31
Class template simple_segregated_storage, 41, 43, 44, 45
Guaranteeing Alignment - How we guarantee alignment portably., 13, 14
Header < boost/pool/simple_segregated_storage.hpp >, 41
How Contiguous Chunks are Handled, 15
pool, 4
Segregation, 16
Simple Segregated Storage, 12
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 26
Symbol Table, 16
The UserAllocator Concept, 21
UserAllocator Requirements, 21
Boost Pool Interfaces - What interfaces are provided and when to use each one.
allocation, 3
block, 3
chunk, 3
concepts, 3
interface, 3
memory, 3
objects, 3
ordered, 3
singleton, 3
BOOST_POOL_VALIDATE_INTERNALS
Header < boost/pool/simple_segregated_storage.hpp >, 41
Macro BOOST_POOL_VALIDATE_INTERNALS, 45
60
build
Installation, 3
Building the Test Programs
jamfile, 3
C
chunk
Allocation and Deallocation, 16
Basic ideas behind pooling, 10
Boost Pool Interfaces - What interfaces are provided and when to use each one., 3
Class template fast_pool_allocator, 37, 38
Class template object_pool, 23, 24, 25
Class template pool, 26, 27, 28, 29, 30, 31
Class template simple_segregated_storage, 41, 42, 43, 44, 45
Class template singleton_pool, 46, 48
Guaranteeing Alignment - How we guarantee alignment portably., 13, 14
Header < boost/pool/pool.hpp >, 25
Header < boost/pool/simple_segregated_storage.hpp >, 41
How Contiguous Chunks are Handled, 15
Introduction, 2
Object_pool, 6
pool, 4
Segregation, 16
Simple Segregated Storage, 12
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Symbol Table, 16
The UserAllocator Concept, 21
Class template fast_pool_allocator
address, 37, 39
allocate, 37, 39
chunk, 37, 38
construct, 37, 38
const_pointer, 37
const_reference, 37
deallocate, 37, 39
destroy, 37, 38
difference_type, 37
fast_pool_allocator, 37
headers, 37
main, 38
max_size, 37, 39
memory, 38, 39
mutex, 37
objects, 38
other, 37
pointer, 37
rebind, 37
reference, 37
singleton, 38
singleton_pool, 38
size, 37, 38, 39
size_type, 37
template, 37, 38, 40
user_allocator, 37
value_type, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>
61
const_pointer, 40
fast_pool_allocator, 40
headers, 40
other, 40
pointer, 40
rebind, 40
template, 40
value_type, 40
Class template object_pool
allocation, 22, 24
automatic, 22
block, 23
chunk, 23, 24, 25
construct, 22, 24
destroy, 22, 24
difference_type, 22
element_type, 22
free, 22, 23
headers, 22
include, 24
is_from, 22, 24
malloc, 22, 23
memory, 22, 23, 24, 25
new, 23, 25
nextof, 22, 23
objects, 22, 23, 24
object_pool, 22, 23
pool, 22
segregated, 23
set_next_size, 22, 25
size, 22, 23, 24, 25
size_type, 22
template, 22, 24
user_allocator, 22
Class template pool
alignment, 26
allocation, 27, 29, 31
block, 28, 29, 30, 31
chunk, 26, 27, 28, 29, 30, 31
difference_type, 27
free, 27, 30
headers, 27
is_from, 27, 29, 31
malloc, 27, 28, 30, 31
malloc_need_resize, 27, 28
memory, 26, 27, 28, 29, 30
new, 28, 30
nextof, 27, 29
objects, 27, 28, 29, 30
ordered, 27, 28, 29, 30, 31
ordered_free, 27, 30, 31
ordered_malloc, 27, 30
ordered_malloc_need_resize, 27, 28
pool, 27
purge_memory, 27, 29
release_memory, 27, 29
segregated, 27, 28, 29
set_max_size, 27, 30
62
set_next_size, 27, 29
simple_segregated_storage, 27
size, 27, 28, 29, 30, 31
size_type, 27
template, 26, 27
user_allocator, 27
Class template pool_allocator
address, 33, 34
allocate, 33, 35
construct, 33, 34
const_pointer, 33
const_reference, 33
deallocate, 33, 35
destroy, 33, 35
difference_type, 33
headers, 33
main, 33
max_size, 33, 34
memory, 33
mutex, 33
objects, 33
other, 33
pointer, 33
pool_allocator, 33
rebind, 33
reference, 33
singleton, 33, 34
singleton_pool, 33, 34
size, 33, 34, 35
size_type, 33
template, 32, 33, 34, 35
user_allocator, 33
value_type, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>
const_pointer, 36
headers, 36
other, 36
pointer, 36
pool_allocator, 36
rebind, 36
template, 35, 36
value_type, 36
Class template simple_segregated_storage
add_block, 42, 43
add_ordered_block, 42, 44
alignment, 42
allocation, 41
block, 41, 43, 44, 45
chunk, 41, 42, 43, 44, 45
deallocation, 41
find_prev, 42, 43
free, 42, 44
free_n, 42, 44
headers, 42
malloc, 42, 44
malloc_n, 42, 44
memory, 41, 42, 44
nextof, 42, 43
63
objects, 42, 45
ordered, 42, 43, 44
ordered_free, 42, 44
ordered_free_n, 42, 44
segregate, 42, 45
segregated, 41, 42, 43, 44, 45
simple_segregated_storage, 42
size, 41, 42, 43, 44, 45
size_type, 42
template, 41, 42
try_malloc_n, 42, 43
Class template singleton_pool
allocation, 46
chunk, 46, 48
difference_type, 46
free, 46, 48
get_pool, 46, 48
headers, 46
interface, 46
is_from, 46, 48
main, 46
malloc, 46, 47
memory, 46
mutex, 46
objects, 46
object_creator, 46
ordered, 46, 48
ordered_free, 46, 48
ordered_malloc, 46, 48
purge_memory, 46, 48
release_memory, 46, 48
singleton, 45, 46, 47, 48
singleton_pool, 45, 46, 47, 48
size, 46, 48
size_type, 46
tag, 46, 47
template, 45, 46, 47
user_allocator, 46
concepts
Appendix F: Other Implementations, 51
Boost Pool Interfaces - What interfaces are provided and when to use each one., 3
Documentation Naming and Formatting Conventions, 2
Guaranteeing Alignment - How we guarantee alignment portably., 13
Introduction, 2
The UserAllocator Concept, 21
construct
Class template fast_pool_allocator, 37, 38
Class template object_pool, 22, 24
Class template pool_allocator, 33, 34
Object_pool, 6
pool_allocator, 8
Constructors, Destructors, and State
new, 16
ordered, 16
const_pointer
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template pool_allocator, 33
64
D
deallocate
Class template fast_pool_allocator, 37, 39
Class template pool_allocator, 33, 35
pool_allocator, 8
deallocation
Allocation and Deallocation, 16
Appendix B: FAQ, 50
Class template simple_segregated_storage, 41
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/simple_segregated_storage.hpp >, 41
Introduction, 2
Simple Segregated Storage, 12
default_user_allocator_malloc_free
pool, 4
Struct default_user_allocator_malloc_free, 26
default_user_allocator_new_delete
pool, 4
Struct default_user_allocator_new_delete, 25
destroy
Class template fast_pool_allocator, 37, 38
Class template object_pool, 22, 24
Class template pool_allocator, 33, 35
Object_pool, 6
pool_allocator, 8
difference_type
Class template fast_pool_allocator, 37
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator, 33
Class template singleton_pool, 46
Object_pool, 6
pool, 4
pool_allocator, 8
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25
Documentation Naming and Formatting Conventions
concepts, 2
conventions, 2
include, 2
naming, 2
objects, 2
template, 2
E
elements
Guaranteeing Alignment - How we guarantee alignment portably., 13
65
element_type
Class template object_pool, 22
Object_pool, 6
F
fast_pool_allocator
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
pool_allocator, 8
Struct template rebind, 40, 41
fast_pool_allocator_tag
pool_allocator, 8
Struct fast_pool_allocator_tag, 37
find_prev
Class template simple_segregated_storage, 42, 43
free
Class template object_pool, 22, 23
Class template pool, 27, 30
Class template simple_segregated_storage, 42, 44
Class template singleton_pool, 46, 48
Object_pool, 6
pool, 4
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25, 26
free_n
Class template simple_segregated_storage, 42, 44
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
G
get_pool
Class template singleton_pool, 46, 48
Guaranteeing Alignment - How we guarantee alignment portably.
address, 13
alignment, 13
allocation, 13
automatic, 13
block, 13, 14
chunk, 13, 14
concepts, 13
elements, 13
memory, 13, 14
new, 13
objects, 13, 14
overview, 13
padding, 13
portable, 13
segregated, 13
size, 13, 14
sizeof, 13
H
Header < boost/pool/object_pool.hpp >
allocation, 22
automatic, 22
headers, 22
66
memory, 22
objects, 22
object_pool, 22
template, 22
Header < boost/pool/pool.hpp >
alignment, 25
chunk, 25
headers, 25
memory, 25
segregated, 25
template, 25
Header < boost/pool/poolfwd.hpp >
headers, 41
Header < boost/pool/pool_alloc.hpp >
allocation, 31
deallocation, 31
headers, 31
interface, 31
main, 31
memory, 31
singleton, 31
size, 31
sizeof, 31
template, 31
Header < boost/pool/simple_segregated_storage.hpp >
allocation, 41
block, 41
BOOST_POOL_VALIDATE_INTERNALS, 41
chunk, 41
deallocation, 41
headers, 41
memory, 41
objects, 41
segregated, 41
size, 41
template, 41
Header < boost/pool/singleton_pool.hpp >
headers, 45
interface, 45
objects, 45
singleton, 45
singleton_pool, 45
size, 45
template, 45
headers
Basic ideas behind pooling, 10
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
Class template simple_segregated_storage, 42
Class template singleton_pool, 46
Header < boost/pool/object_pool.hpp >, 22
Header < boost/pool/pool.hpp >, 25
Header < boost/pool/poolfwd.hpp >, 41
Header < boost/pool/pool_alloc.hpp >, 31
67
I
include
Class template object_pool, 24
Documentation Naming and Formatting Conventions, 2
How do I use Pool?, 3
Installation, 3
Installation
build, 3
headers, 3
include, 3
installation, 3
installation
Installation, 3
interface
Appendix B: FAQ, 50
Appendix H: Future plans, 52
Boost Pool Interfaces - What interfaces are provided and when to use each one., 3
Class template singleton_pool, 46
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/singleton_pool.hpp >, 45
How do I use Pool?, 3
Introduction, 2
Object_pool, 6
pool, 4
Pool Interfaces, 4
pool_allocator, 8
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
The UserAllocator Concept, 21
Introduction
68
allocation, 2
chunk, 2
concepts, 2
deallocation, 2
interface, 2
memory, 2
objects, 2
segregated, 2
Introduction and Overview
overview, 2
is_from
Class template object_pool, 22, 24
Class template pool, 27, 29, 31
Class template singleton_pool, 46, 48
Object_pool, 6
pool, 4
Singleton_pool, 7
J
jamfile
Building the Test Programs, 3
M
Macro BOOST_POOL_VALIDATE_INTERNALS
BOOST_POOL_VALIDATE_INTERNALS, 45
headers, 45
segregated, 45
main
Class template fast_pool_allocator, 38
Class template pool_allocator, 33
Class template singleton_pool, 46
Header < boost/pool/pool_alloc.hpp >, 31
Singleton_pool, 7
malloc
Allocation and Deallocation, 16
Appendix G: References, 51
Basic ideas behind pooling, 10
Class template object_pool, 22, 23
Class template pool, 27, 28, 30, 31
Class template simple_segregated_storage, 42, 44
Class template singleton_pool, 46, 47
Object_pool, 6
pool, 4
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25, 26
UserAllocator Requirements, 21
malloc_n
Class template simple_segregated_storage, 42, 44
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
malloc_need_resize
Class template pool, 27, 28
max_size
Class template fast_pool_allocator, 37, 39
Class template pool_allocator, 33, 34
pool_allocator, 8
69
memory
Appendix B: FAQ, 50
Appendix G: References, 51
Basic ideas behind pooling, 10
Boost Pool Interfaces - What interfaces are provided and when to use each one., 3
Class template fast_pool_allocator, 38, 39
Class template object_pool, 22, 23, 24, 25
Class template pool, 26, 27, 28, 29, 30
Class template pool_allocator, 33
Class template simple_segregated_storage, 41, 42, 44
Class template singleton_pool, 46
Guaranteeing Alignment - How we guarantee alignment portably., 13, 14
Header < boost/pool/object_pool.hpp >, 22
Header < boost/pool/pool.hpp >, 25
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/simple_segregated_storage.hpp >, 41
How Contiguous Chunks are Handled, 15
Introduction, 2
Object_pool, 6
pool, 4
pool_allocator, 8
Segregation, 16
Simple Segregated Storage, 12
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_new_delete, 25
The UserAllocator Concept, 21
UserAllocator Requirements, 21
mutex
Class template fast_pool_allocator, 37
Class template pool_allocator, 33
Class template singleton_pool, 46
N
naming
Documentation Naming and Formatting Conventions, 2
new
Basic ideas behind pooling, 10
Class template object_pool, 23, 25
Class template pool, 28, 30
Constructors, Destructors, and State, 16
Guaranteeing Alignment - How we guarantee alignment portably., 13
pool, 4
Struct default_user_allocator_new_delete, 25
nextof
Class template object_pool, 22, 23
Class template pool, 27, 29
Class template simple_segregated_storage, 42, 43
O
objects
Appendix B: FAQ, 50
Appendix F: Other Implementations, 51
Basic ideas behind pooling, 10
Boost Pool Interfaces - What interfaces are provided and when to use each one., 3
Class template fast_pool_allocator, 38
Class template object_pool, 22, 23, 24
70
71
P
padding
Guaranteeing Alignment - How we guarantee alignment portably., 13
How Contiguous Chunks are Handled, 15
pointer
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
pool_allocator, 8
pool
alignment, 4
block, 4
chunk, 4
Class template object_pool, 22
Class template pool, 27
default_user_allocator_malloc_free, 4
default_user_allocator_new_delete, 4
difference_type, 4
free, 4
interface, 4
is_from, 4
malloc, 4
72
memory, 4
new, 4
objects, 4
ordered, 4
ordered_free, 4
ordered_malloc, 4
pool, 4
purge_memory, 4
release_memory, 4
segregated, 4
size, 4
size_type, 4
template, 4
user_allocator, 4
Pool Interfaces
interface, 4
pool_allocator
address, 8
allocate, 8
allocation, 8
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
construct, 8
const_pointer, 8
const_reference, 8
deallocate, 8
destroy, 8
difference_type, 8
fast_pool_allocator, 8
fast_pool_allocator_tag, 8
interface, 8
max_size, 8
memory, 8
objects, 8
ordered, 8
other, 8
pointer, 8
pool_allocator, 8
pool_allocator_tag, 8
rebind, 8
reference, 8
singleton, 8
singleton_pool, 8
size, 8
size_type, 8
Struct template rebind, 35, 36
template, 8
user_allocator, 8
value_type, 8
pool_allocator_tag
pool_allocator, 8
Struct pool_allocator_tag, 32
portable
Appendix F: Other Implementations, 51
Guaranteeing Alignment - How we guarantee alignment portably., 13
purge_memory
Class template pool, 27, 29
Class template singleton_pool, 46, 48
73
pool, 4
Singleton_pool, 7
R
rebind
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
pool_allocator, 8
Struct template rebind, 35, 36, 40, 41
reference
Class template fast_pool_allocator, 37
Class template pool_allocator, 33
pool_allocator, 8
release_memory
Class template pool, 27, 29
Class template singleton_pool, 46, 48
pool, 4
Singleton_pool, 7
S
segregate
Class template simple_segregated_storage, 42, 45
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
segregated
Appendix F: Other Implementations, 51
Appendix G: References, 51
Basic ideas behind pooling, 10
Class template object_pool, 23
Class template pool, 27, 28, 29
Class template simple_segregated_storage, 41, 42, 43, 44, 45
Guaranteeing Alignment - How we guarantee alignment portably., 13
Header < boost/pool/pool.hpp >, 25
Header < boost/pool/simple_segregated_storage.hpp >, 41
Introduction, 2
Macro BOOST_POOL_VALIDATE_INTERNALS, 45
pool, 4
Simple Segregated Storage, 12
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Symbol Table, 16
Segregation
block, 16
chunk, 16
memory, 16
objects, 16
ordered, 16
size, 16
set_max_size
Class template pool, 27, 30
set_next_size
Class template object_pool, 22, 25
Class template pool, 27, 29
Simple Segregated Storage
allocation, 12
block, 12
chunk, 12
74
deallocation, 12
memory, 12
objects, 12
segregated, 12
size, 12
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!)
add_block, 16
add_ordered_block, 16
alignment, 16
block, 16
chunk, 16
free, 16
free_n, 16
interface, 16
malloc, 16
malloc_n, 16
memory, 16
objects, 16
ordered, 16
ordered_free, 16
ordered_free_n, 16
segregate, 16
segregated, 16
simple_segregated_storage, 16
size, 16
size_type, 16
template, 16
simple_segregated_storage
Class template pool, 27
Class template simple_segregated_storage, 42
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
singleton
Appendix H: Future plans, 52
Boost Pool Interfaces - What interfaces are provided and when to use each one., 3
Class template fast_pool_allocator, 38
Class template pool_allocator, 33, 34
Class template singleton_pool, 45, 46, 47, 48
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/singleton_pool.hpp >, 45
pool_allocator, 8
Singleton_pool, 7
Struct fast_pool_allocator_tag, 36
Struct object_creator, 48, 49
Struct pool_allocator_tag, 32
Singleton_pool
chunk, 7
difference_type, 7
free, 7
interface, 7
is_from, 7
main, 7
malloc, 7
memory, 7
objects, 7
ordered, 7
ordered_free, 7
ordered_malloc, 7
purge_memory, 7
75
release_memory, 7
singleton, 7
singleton_pool, 7
size, 7
size_type, 7
tag, 7
template, 7
user_allocator, 7
singleton_pool
Appendix H: Future plans, 52
Class template fast_pool_allocator, 38
Class template pool_allocator, 33, 34
Class template singleton_pool, 45, 46, 47, 48
Header < boost/pool/singleton_pool.hpp >, 45
pool_allocator, 8
Singleton_pool, 7
Struct fast_pool_allocator_tag, 36
Struct object_creator, 48, 49
Struct pool_allocator_tag, 32
size
Allocation and Deallocation, 16
Basic ideas behind pooling, 10
Class template fast_pool_allocator, 37, 38, 39
Class template object_pool, 22, 23, 24, 25
Class template pool, 27, 28, 29, 30, 31
Class template pool_allocator, 33, 34, 35
Class template simple_segregated_storage, 41, 42, 43, 44, 45
Class template singleton_pool, 46, 48
Guaranteeing Alignment - How we guarantee alignment portably., 13, 14
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/simple_segregated_storage.hpp >, 41
Header < boost/pool/singleton_pool.hpp >, 45
How Contiguous Chunks are Handled, 15
Object_pool, 6
pool, 4
pool_allocator, 8
Segregation, 16
Simple Segregated Storage, 12
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25
Symbol Table, 16
Template Parameters, 16
The UserAllocator Concept, 21
Typedefs, 16
UserAllocator Requirements, 21
sizeof
Guaranteeing Alignment - How we guarantee alignment portably., 13
Header < boost/pool/pool_alloc.hpp >, 31
How Contiguous Chunks are Handled, 15
size_type
Class template fast_pool_allocator, 37
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator, 33
Class template simple_segregated_storage, 42
Class template singleton_pool, 46
76
Object_pool, 6
pool, 4
pool_allocator, 8
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25
Struct default_user_allocator_malloc_free
block, 26
default_user_allocator_malloc_free, 26
difference_type, 26
free, 26
headers, 26
malloc, 26
objects, 26
object_pool, 26
size, 26
size_type, 26
template, 26
Struct default_user_allocator_new_delete
block, 26
default_user_allocator_new_delete, 25
difference_type, 25
free, 25, 26
headers, 25
malloc, 25, 26
memory, 25
new, 25
objects, 25
size, 25
size_type, 25
template, 25
Struct fast_pool_allocator_tag
fast_pool_allocator_tag, 37
headers, 37
singleton, 36
singleton_pool, 36
template, 36
Struct object_creator
headers, 49
objects, 48, 49
object_creator, 49
singleton, 48, 49
singleton_pool, 48, 49
Struct pool_allocator_tag
headers, 32
pool_allocator_tag, 32
singleton, 32
singleton_pool, 32
Struct template rebind
fast_pool_allocator, 40, 41
headers, 35, 36, 40, 41
other, 35, 36, 40, 41
pool_allocator, 35, 36
rebind, 35, 36, 40, 41
template, 35, 36, 39, 40, 41
Symbol Table
block, 16
77
chunk, 16
segregated, 16
size, 16
T
tag
Class template singleton_pool, 46, 47
Singleton_pool, 7
template
Class template fast_pool_allocator, 37, 38, 40
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template object_pool, 22, 24
Class template pool, 26, 27
Class template pool_allocator, 32, 33, 34, 35
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 35, 36
Class template simple_segregated_storage, 41, 42
Class template singleton_pool, 45, 46, 47
Documentation Naming and Formatting Conventions, 2
Header < boost/pool/object_pool.hpp >, 22
Header < boost/pool/pool.hpp >, 25
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/simple_segregated_storage.hpp >, 41
Header < boost/pool/singleton_pool.hpp >, 45
Object_pool, 6
pool, 4
pool_allocator, 8
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25
Struct fast_pool_allocator_tag, 36
Struct template rebind, 35, 36, 39, 40, 41
Template Parameters, 16
The UserAllocator Concept, 21
Template Parameters
size, 16
template, 16
try_malloc_n
Class template simple_segregated_storage, 42, 43
Typedefs
size, 16
U
UserAllocator Concept
block, 21
chunk, 21
concepts, 21
interface, 21
memory, 21
objects, 21
size, 21
template, 21
UserAllocator Requirements
block, 21
malloc, 21
memory, 21
objects, 21
78
size, 21
user_allocator
Class template fast_pool_allocator, 37
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator, 33
Class template singleton_pool, 46
Object_pool, 6
pool, 4
pool_allocator, 8
Singleton_pool, 7
V
value_type
Class template fast_pool_allocator, 37
Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 40
Class template pool_allocator, 33
Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36
pool_allocator, 8
79