0% found this document useful (0 votes)
13 views79 pages

Pool

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views79 pages

Pool

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

Boost.

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Introduction and Overview


Documentation Naming and Formatting Conventions
This documentation makes use of the following naming and formatting conventions.

• Code is in fixed width font and is syntax-highlighted in color.

• Replaceable text that you will need to supply is in italics.

• 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:

// Include all of Pool files


#include <boost/pool.hpp>

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).

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.

When should I use Pool?

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.

Which pool allocator should I use?

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.

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

How do I use Pool?


See the Pool Interfaces section that covers the different Pool interfaces supplied by this library.

Library Structure and Dependencies

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.

Every header used only by the implementation is in the subdirectory /detail/.

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!

Building the Test Programs


A jamfile.v2 is provided which can be run is the usual way, for example:

boost\libs\pool\test> bjam -a >pool_test.log

Boost Pool Interfaces - What interfaces are provided and when


to use each one.
Introduction
There are several interfaces provided which allow users great flexibility in how they want to use Pools. Review the concepts document
to get the basic understanding of how the various pools work.

Terminology and Tradeoffs


Object Usage vs. Singleton Usage

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.

Out-of-Memory Conditions: Exceptions vs. Null Return

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.

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Ordered versus unordered

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.

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

struct default_user_allocator_new_delete
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;

static char * malloc(const size_type bytes)


{ return new (std::nothrow) char[bytes]; }
static void free(char * const block)
{ delete [] block; }
};

struct default_user_allocator_malloc_free
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;

static char * malloc(const size_type bytes)


{ return reinterpret_cast<char *>(std::malloc(bytes)); }
static void free(char * const block)
{ std::free(block); }
};

template <typename UserAllocator = default_user_allocator_new_delete>


class pool
{
private:
pool(const pool &);
void operator=(const pool &);

public:
typedef UserAllocator user_allocator;
typedef typename UserAllocator::size_type size_type;
typedef typename UserAllocator::difference_type difference_type;

explicit pool(size_type requested_size);


~pool();

bool release_memory();
bool purge_memory();

bool is_from(void * chunk) const;


size_type get_requested_size() const;

void * malloc();
void * ordered_malloc();
void * ordered_malloc(size_type n);

void free(void * chunk);


void ordered_free(void * chunk);
void free(void * chunks, size_type n);
void ordered_free(void * chunks, size_type n);
};

Example:

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

template <typename ElementType, typename UserAllocator = default_user_allocator_new_delete>


class object_pool
{
private:
object_pool(const object_pool &);
void operator=(const object_pool &);

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.

Example: struct X { ... }; // has destructor with side-effects.

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

template <typename Tag, unsigned RequestedSize,


typename UserAllocator = default_user_allocator_new_delete>
struct singleton_pool
{
public:
typedef Tag tag;
typedef UserAllocator user_allocator;
typedef typename pool<UserAllocator>::size_type size_type;
typedef typename pool<UserAllocator>::difference_type difference_type;

static const unsigned requested_size = RequestedSize;

private:
static pool<size_type> p; // exposition only!

singleton_pool();

public:
static bool is_from(void * ptr);

static void * malloc();


static void * ordered_malloc();
static void * ordered_malloc(size_type n);

static void free(void * ptr);


static void ordered_free(void * ptr);
static void free(void * ptr, std::size_t n);
static void ordered_free(void * ptr, size_type n);

static bool release_memory();


static bool purge_memory();
};

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.

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

Tag is never actually used by 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.

Example: struct MyPoolTag { };

typedef boost::singleton_pool<MyPoolTag, sizeof(int)> my_pool;


void func()
{
for (int i = 0; i < 10000; ++i)
{
int * const t = my_pool::malloc();
... // Do something with t; don't take the time to free() it.
}
// Explicitly free all malloc()'ed ints.
my_pool::purge_memory();
}

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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;

template <typename U>


struct rebind
{ typedef pool_allocator<U, UserAllocator> other; };

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();

static pointer address(reference r);


static const_pointer address(const_reference s);
static size_type max_size();
static void construct(pointer ptr, const value_type & t);
static void destroy(pointer ptr);

bool operator==(const pool_allocator &) const;


bool operator!=(const pool_allocator &) const;

static pointer allocate(size_type n);


static pointer allocate(size_type n, pointer);
static void deallocate(pointer ptr, size_type n);
};

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;

template <typename U>


struct rebind
{ typedef fast_pool_allocator<U, UserAllocator> other; };

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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();

static pointer address(reference r);


static const_pointer address(const_reference s);
static size_type max_size();
static void construct(pointer ptr, const value_type & t);
static void destroy(pointer ptr);

bool operator==(const fast_pool_allocator &) const;


bool operator!=(const fast_pool_allocator &) const;

static pointer allocate(size_type n);


static pointer allocate(size_type n, pointer);
static void deallocate(pointer ptr, size_type n);

static pointer allocate();


static void deallocate(pointer ptr);
};

Template Parameters

T The first template parameter is the type of object to allocate/deallocate.

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.

Pool in More Depth


Basic ideas behind pooling
Dynamic memory allocation has been a fundamental part of most computer systems since roughly 1960... 1

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

Dynamic memory allocation is often inefficient

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Simple Segregated Storage


Simple Segregated Storage is the basic idea behind the Boost Pool library. Simple Segregated 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. To illustrate:

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

Guaranteeing Alignment - How we guarantee alignment portably.


Terminology
Review the concepts section if you are not already familiar with it. Remember that block is a contiguous section of memory, which
is partitioned or segregated into fixed-size chunks. These chunks are what are allocated and deallocated by the user.

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.

Proof of Concept: Guaranteeing Alignment


Each block of memory is allocated as a POD type (specifically, an array of characters) through operator new[]. Let POD_size
be the number of characters allocated.

Predicate 1: Arrays may not have padding

This follows from the following quote:

[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

This follows from:

• [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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

Corollary 1: The block is properly aligned for an array of Elements

This follows from Predicates 1 and 2, and the following quote:

[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."

(Specifically, array types are object types.)

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.

Use of the Theorem


The proof above covers alignment requirements for cutting chunks out of a block. The implementation uses actual object sizes of:

• 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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

A Look at the Memory Block


Each memory block consists of three main sections. The first section is the part that chunks are cut out of, and contains the interleaved
free list. The second section is the pointer to the next block, and the third section is the size of the next block.

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).

Here's an example memory block, where requested_size == sizeof(void *) == sizeof(size_type) == 4:

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

How Contiguous Chunks are Handled


The theorem above guarantees all alignment requirements for allocating chunks and also implementation details such as the interleaved
free list. However, it does so by adding padding when necessary; therefore, we have to treat allocations of contiguous chunks in a
different way.

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Here's an example memory block, where requested_size == 1 and sizeof(void *) == sizeof(size_type) == 4:

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Synopsis

template <typename SizeType = std::size_t>


class simple_segregated_storage
{
private:
simple_segregated_storage(const simple_segregated_storage &);
void operator=(const simple_segregated_storage &);

public:
typedef SizeType size_type;

simple_segregated_storage();
~simple_segregated_storage();

static void * segregate(void * block,


size_type nsz, size_type npartition_sz,
void * end = 0);
void add_block(void * block,
size_type nsz, size_type npartition_sz);
void add_ordered_block(void * block,
size_type nsz, size_type npartition_sz);

bool empty() const;

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).

Table 1. Symbol Table

Symbol Meaning

Store simple_segregated_storage<SizeType>

t value of type Store

u value of type const Store

block, chunk, end values of type void *

partition_sz, sz, n values of type Store::size_type

17

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Table 2. Template Parameters

Parameter Default Requirements

SizeType std::size_t An unsigned integral type

Table 3. Typedefs

Symbol Type

size_type SizeType

Table 4. Constructors, Destructors, and State

Expression Return Type Post-Condition Notes

Store() not used empty() Constructs a new Store

(&t)->~Store() not used Destructs the Store

u.empty() bool Returns true if u is empty. Or-


der-preserving.

18

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Table 5. Segregation

Expression Return Type Pre-Condition Post-Condition Semantic Equival- Notes


ence

Store::segreg- void * partition_sz >= Interleaves a free


ate(block, sz, parti- sizeof(void *) parti- list through the
tion_sz, end) tion_sz = memory block spe-
sizeof(void *) * i, cified by block of
for some integer i size sz bytes, parti-
sz >= partition_sz tioning it into as
block is properly many partition_sz-
aligned for an array sized chunks as
of objects of size possible. The last
partition_sz block chunk is set to
is properly aligned point to end, and a
for an array of void pointer to the first
* chunck is returned
(this is always
equal to block).
This interleaved
free list is ordered.
O(sz).

Store::segreg- void * Same as above Store::segreg-


ate(block, sz, parti- ate(block, sz, parti-
tion_sz) tion_sz, 0)

t.add_block(block, void Same as above !t.empty() Segregates the


sz, partition_sz) memory block spe-
cified by block of
size sz bytes into
partition_sz-sized
chunks, and adds
that free list to its
own. If t was
empty before this
call, then it is
ordered after this
call. O(sz).

t.add_ordered_block(block, void Same as above !t.empty() Segregates the


sz, partition_sz) memory block spe-
cified by block of
size sz bytes into
partition_sz-sized
chunks, and merges
that free list into its
own. Order-pre-
serving. O(sz).

19

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Table 6. Allocation and Deallocation

Expression Return Type Pre-Condition Post-Condition Semantic Equival- Notes


ence

t.malloc() void * !t.empty() Takes the first


available chunk
from the free list
and returns it. Or-
d e r- p r e s e r v i n g .
O(1).

t.free(chunk) void chunk was previ- !t.empty() Places chunk back


ously returned on the free list.
from a call to Note that chunk
t.malloc() may not be 0. O(1).

t.ordered_free(chunk) void Same as above !t.empty() Places chunk back


on the free list.
Note that chunk
may not be 0. Or-
d e r- p r e s e r v i n g .
O(N) with respect
to the size of the
free list.

t.malloc_n(n, parti- void * Attempts to find a


tion_sz) contiguous se-
quence of n parti-
tion_sz-sized
chunks. If found,
removes them all
from the free list
and returns a point-
er to the first. If not
found, returns 0. It
is strongly recom-
mended (but not re-
quired) that the free
list be ordered, as
this algorithm will
fail to find a con-
tiguous sequence
unless it is contigu-
ous in the free list
as well. Order-pre-
serving. O(N) with
respect to the size
of the free list.

20

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Expression Return Type Pre-Condition Post-Condition Semantic Equival- Notes


ence

t.free_n(chunk, n, void chunk was previ- !t.empty() t.add_block(chunk, Assumes that


partition_sz) ously returned n * partition_sz, chunk actually
from a call to partition_sz) refers to a block of
t.malloc_n(n, parti- chunks spanning n
tion_sz) * partition_sz
bytes; segregates
and adds in that
block. Note that
chunk may not be
0. O(n).

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.

The UserAllocator Concept


Pool objects need to request memory blocks from the system, which the Pool then splits into chunks to allocate to the user. By spe-
cifying a UserAllocator template parameter to various Pool interfaces, users can control how those system memory blocks are allocated.

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

Table 7. UserAllocator Requirements

Expression Result Description

UserAllocator::size_type An unsigned integral type that can repres-


ent the size of the largest object to be al-
located.

UserAllocator::difference_type A signed integral type that can represent


the difference of any two pointers.

UserAllocator::malloc(n) char * Attempts to allocate n bytes from the


system. Returns 0 if out-of-memory.

UserAllocator::free(block) void block must have been previously returned


from a call to UserAllocator::malloc.

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Boost.Pool C++ Reference


Header <boost/pool/object_pool.hpp>
Provides a template type boost::object_pool<T, UserAllocator> that can be used for fast and efficient memory allocation of objects
of type T. It also provides automatic destruction of non-deallocated objects.

namespace boost {
template<typename T, typename UserAllocator> class object_pool;
}

Class template object_pool


boost::object_pool — A template class that can be used for fast and efficient memory allocation of objects. It also provides automatic
destruction of non-deallocated objects.

Synopsis
// In header: <boost/pool/object_pool.hpp>

template<typename T, typename UserAllocator>


class object_pool : protected boost::pool< UserAllocator > {
public:
// types
typedef T element_type; // ElementType.
typedef UserAllocator user_allocator; // User allocator.
typedef pool< UserAllocator >::size_type size_type; // pool<UserAllocat↵
or>::size_type
typedef pool< UserAllocator >::difference_type difference_type; // pool<UserAllocator>::dif↵
ference_type

// construct/copy/destruct
explicit object_pool(const size_type = 32, const size_type = 0);
~object_pool();

// protected member functions


pool< UserAllocator > & store();
const pool< UserAllocator > & store() const;

// protected static functions


static void *& nextof(void *const);

// public member functions


element_type * malloc();
void free(element_type *const);
bool is_from(element_type *const) const;
element_type * construct();
template<typename Arg1, ...class ArgN>
element_type * construct(Arg1 &, ...ArgN &);
void destroy(element_type *const);
size_type get_next_size() const;
void set_next_size(const size_type);
};

Description
T The type of object to allocate/deallocate. T must have a non-throwing destructor.

22

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

object_pool public construct/copy/destruct

1.
explicit object_pool(const size_type arg_next_size = 32,
const size_type arg_max_size = 0);

Constructs a new (empty by default) ObjectPool.


Requires: next_size != 0.

2.
~object_pool();

object_pool protected member functions

1.
pool< UserAllocator > & store();

Returns: The underlying boost:: pool storage used by *this.

2.
const pool< UserAllocator > & store() const;

Returns: The underlying boost:: pool storage used by *this.

object_pool protected static functions

1.
static void *& nextof(void *const ptr);

Returns: The next memory block after ptr (for the sake of code readability :)

object_pool public member functions

1.
element_type * malloc();

Allocates memory that can hold one object of type ElementType.

If out of memory, returns 0.

Amortized O(1).

2.
void free(element_type *const chunk);

De-Allocates memory that holds a chunk of type ElementType.

23

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Note that p may not be 0.

Note that the destructor for p is not called. O(N).

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.

Otherwise, the return value is meaningless.

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);

Destroys an object allocated with construct.

Equivalent to:

p->~ElementType(); this->free(p);

24

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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;

template<typename UserAllocator> class pool;


}

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.

// public static functions


static char * malloc(const size_type);
static void free(char *const);
};

Description
default_user_allocator_new_delete public static functions

1.
static char * malloc(const size_type bytes);

Attempts to allocate n bytes from the system. Returns 0 if out-of-memory

25

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

2.
static void free(char *const block);

Attempts to de-allocate block.


Requires: Block must have been previously returned from a call to UserAllocator::malloc.

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.

// public static functions


static char * malloc(const size_type);
static void free(char *const);
};

Description
default_user_allocator_malloc_free public static functions

1.
static char * malloc(const size_type bytes);

2.
static void free(char *const block);

Class template pool


boost::pool — A fast memory allocator that guarantees proper alignment of all allocated chunks.

26

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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();

// private member functions


void * malloc_need_resize();
void * ordered_malloc_need_resize();

// protected member functions


simple_segregated_storage< size_type > & store();
const simple_segregated_storage< size_type > & store() const;
details::PODptr< size_type > find_POD(void *const) const;
size_type alloc_size() const;

// protected static functions


static bool is_from(void *const, char *const, const size_type);
static void *& nextof(void *const);

// public member functions


bool release_memory();
bool purge_memory();
size_type get_next_size() const;
void set_next_size(const size_type);
size_type get_max_size() const;
void set_max_size(const size_type);
size_type get_requested_size() const;
void * malloc();
void * ordered_malloc();
void * ordered_malloc(size_type);
void free(void *const);
void ordered_free(void *const);
void free(void *const, const size_type);
void ordered_free(void *const, const size_type);
bool is_from(void *const) const;
};

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

pool public construct/copy/destruct

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();

Destructs the Pool, freeing its list of memory blocks.

pool private member functions

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();

Called if malloc needs to resize the free list.

No memory in any of our storages; make a new storage,


Returns: pointer to new chunk.

pool protected member functions

1.
simple_segregated_storage< size_type > & store();

Returns: pointer to store.

2.
const simple_segregated_storage< size_type > & store() const;

Returns: pointer to store.

28

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

3.
details::PODptr< size_type > find_POD(void *const chunk) const;

finds which POD in the list 'chunk' was allocated from.

find which PODptr storage memory that this chunk is from.


Returns: the PODptr that holds this chunk.

4.
size_type alloc_size() const;

Calculated size of the memory chunks that will be allocated by this Pool.
Returns: allocated size.

pool protected static functions

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 :)

pool public member functions

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();

pool must be ordered. Frees every memory block.

This function invalidates any pointers previously returned by allocation functions of t.


Returns: true if at least one memory block was freed.

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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);

Gets address of a chunk n, allocating new memory if not already available.


Returns: Address of chunk n if allocated ok.

0 if not enough memory for n chunks.

11.
void free(void *const chunk);

Same as malloc, only allocates enough contiguous chunks to cover n * requested_size bytes. Amortized O(n).

Deallocates a chunk of memory. Note that chunk may not be 0. O(1).

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);

Same as above, but is order-preserving.

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);

Assumes that chunk actually refers to a block of chunks.

30

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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:

Expression Return Type Semantic Equivalence

PoolAlloc::allocate() T * PoolAlloc::allocate(1)

PoolAlloc::dealloc- void PoolAlloc::dealloc-


ate(p) ate(p, 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.

Compiler and STL Notes

31

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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;

template<typename T, typename UserAllocator, typename Mutex,


unsigned NextSize, unsigned MaxSize>
class pool_allocator;

template<typename UserAllocator, typename Mutex, unsigned NextSize,


unsigned MaxSize>
class pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>;

struct fast_pool_allocator_tag;

template<typename T, typename UserAllocator, typename Mutex,


unsigned NextSize, unsigned MaxSize>
class fast_pool_allocator;

template<typename UserAllocator, typename Mutex, unsigned NextSize,


unsigned MaxSize>
class fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>;
}

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.

Class template pool_allocator


boost::pool_allocator — A C++ Standard Library conforming allocator, based on an underlying pool.

32

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

template<typename T, typename UserAllocator, typename Mutex,


unsigned NextSize, unsigned MaxSize>
class pool_allocator {
public:
// types
typedef T value_type; // value_type of template ↵
parameter T.
typedef UserAllocator user_allocator; // allocator that defines ↵
the method that the underlying Pool will use to allocate memory from the system.
typedef Mutex mutex; // typedef mutex publishes ↵
the value of the template parameter Mutex.
typedef value_type * pointer;
typedef const value_type * const_pointer;
typedef value_type & reference;
typedef const value_type & const_reference;
typedef pool< UserAllocator >::size_type size_type;
typedef pool< UserAllocator >::difference_type difference_type;

// member classes/structs/unions

// Nested class rebind allows for transformation from pool_allocator<T> to


// pool_allocator<U>.
template<typename U>
struct rebind {
// types
typedef pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other;
};

// construct/copy/destruct
pool_allocator();
template<typename U>
pool_allocator(const pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &);

// public member functions


bool operator==(const pool_allocator &) const;
bool operator!=(const pool_allocator &) const;

// public static functions


static pointer address(reference);
static const_pointer address(const_reference);
static size_type max_size();
static void construct(const pointer, const value_type &);
static void destroy(const pointer);
static pointer allocate(const size_type);
static pointer allocate(const size_type, const void *);
static void deallocate(const pointer, const size_type);

// public data members


static const unsigned next_size; // next_size publishes the values of the template parameter ↵
NextSize.
};

Description
Template parameters for pool_allocator are defined as follows:

T Type of object to allocate/deallocate.

33

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

MaxSize Limit on the maximum size used.

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.

pool_allocator public construct/copy/destruct

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 .

pool_allocator public member functions

1.
bool operator==(const pool_allocator &) const;

2.
bool operator!=(const pool_allocator &) const;

pool_allocator public static functions

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

Parameters: n bytes to allocate.

8.
static void deallocate(const pointer ptr, const size_type n);

Deallocate n bytes from ptr


Parameters: n number of bytes to deallocate.
ptr location to deallocate from.

Struct template rebind


boost::pool_allocator::rebind — Nested class rebind allows for transformation from pool_allocator<T> to pool_allocator<U>.

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

// Nested class rebind allows for transformation from pool_allocator<T> to


// pool_allocator<U>.
template<typename U>
struct rebind {
// types
typedef pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other;
};

Description
Nested class rebind allows for transformation from pool_allocator<T> to pool_allocator<U> via the member typedef other.

Specializations

• Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>

Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>


boost::pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize> — Specialization of pool_allocator<void>.

35

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

template<typename UserAllocator, typename Mutex, unsigned NextSize,


unsigned MaxSize>
class pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize> {
public:
// types
typedef void * pointer;
typedef const void * const_pointer;
typedef void value_type;

// member classes/structs/unions

// Nested class rebind allows for transformation from pool_allocator<T> to


// pool_allocator<U>.
template<typename U>
struct rebind {
// types
typedef pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other;
};
};

Description
Specialization of pool_allocator for type void: required by the standard to make this a conforming allocator type.

Struct template rebind


boost::pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>::rebind — Nested class rebind allows for transformation
from pool_allocator<T> to pool_allocator<U>.

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

// Nested class rebind allows for transformation from pool_allocator<T> to


// pool_allocator<U>.
template<typename U>
struct rebind {
// types
typedef pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other;
};

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

struct fast_pool_allocator_tag {
};

Class template fast_pool_allocator


boost::fast_pool_allocator — A C++ Standard Library conforming allocator geared towards allocating single chunks.

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

template<typename T, typename UserAllocator, typename Mutex,


unsigned NextSize, unsigned MaxSize>
class fast_pool_allocator {
public:
// types
typedef T value_type;
typedef UserAllocator user_allocator;
typedef Mutex mutex;
typedef value_type * pointer;
typedef const value_type * const_pointer;
typedef value_type & reference;
typedef const value_type & const_reference;
typedef pool< UserAllocator >::size_type size_type;
typedef pool< UserAllocator >::difference_type difference_type;

// member classes/structs/unions

// Nested class rebind allows for transformation from fast_pool_allocator<T>


// to fast_pool_allocator<U>.
template<typename U>
struct rebind {
// types
typedef fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other;
};

// construct/copy/destruct
fast_pool_allocator();
template<typename U>
fast_pool_allocator(const fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &);

// public member functions


void construct(const pointer, const value_type &);
void destroy(const pointer);
bool operator==(const fast_pool_allocator &) const;
bool operator!=(const fast_pool_allocator &) const;

// public static functions


static pointer address(reference);
static const_pointer address(const_reference);
static size_type max_size();
static pointer allocate(const size_type);
static pointer allocate(const size_type, const void *);
static pointer allocate();

37

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

static void deallocate(const pointer, const size_type);


static void deallocate(const pointer);

// public data members


static const unsigned next_size;
};

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.

The template parameters are defined as follows:

T Type of object to allocate/deallocate.

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.

MaxSize Limit on the maximum size used.

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.

fast_pool_allocator public construct/copy/destruct

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 .

fast_pool_allocator public member functions

1.
void construct(const pointer ptr, const value_type & t);

2.
void destroy(const pointer ptr);

38

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Destroy ptr using destructor.

3.
bool operator==(const fast_pool_allocator &) const;

4.
bool operator!=(const fast_pool_allocator &) const;

fast_pool_allocator public static functions

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

Struct template rebind


boost::fast_pool_allocator::rebind — Nested class rebind allows for transformation from fast_pool_allocator<T> to fast_pool_alloc-
ator<U>.

39

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

// Nested class rebind allows for transformation from fast_pool_allocator<T>


// to fast_pool_allocator<U>.
template<typename U>
struct rebind {
// types
typedef fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other;
};

Description
Nested class rebind allows for transformation from fast_pool_allocator<T> to fast_pool_allocator<U> via the member typedef other.

Specializations

• Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>

Class template fast_pool_allocator<void, UserAllocator, Mutex, NextSize,


MaxSize>
boost::fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize> — Specialization of fast_pool_allocator<void>.

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

template<typename UserAllocator, typename Mutex, unsigned NextSize,


unsigned MaxSize>
class fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize> {
public:
// types
typedef void * pointer;
typedef const void * const_pointer;
typedef void value_type;

// member classes/structs/unions

// Nested class rebind allows for transformation from fast_pool_allocator<T>


// to fast_pool_allocator<U>.
template<typename U>
struct rebind {
// types
typedef fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other;
};
};

Description
Specialization of fast_pool_allocator<void> required to make the allocator standard-conforming.

40

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Struct template rebind


boost::fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>::rebind — Nested class rebind allows for transformation
from fast_pool_allocator<T> to fast_pool_allocator<U>.

Synopsis
// In header: <boost/pool/pool_alloc.hpp>

// Nested class rebind allows for transformation from fast_pool_allocator<T>


// to fast_pool_allocator<U>.
template<typename U>
struct rebind {
// types
typedef fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other;
};

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;
}

Class template simple_segregated_storage


boost::simple_segregated_storage — Simple Segregated Storage is the simplest, and probably the fastest, memory allocation/deal-
location algorithm. It is responsible for partitioning a memory block into fixed-size chunks: where the block comes from is determined
by the client of the class.

41

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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 &);

// private static functions


static void * try_malloc_n(void *&, size_type, size_type);

// protected member functions


void * find_prev(void *);

// protected static functions


static void *& nextof(void *const);

// public member functions


void add_block(void *const, const size_type, const size_type);
void add_ordered_block(void *const, const size_type, const size_type);
bool empty() const;
void * malloc();
void free(void *const);
void ordered_free(void *const);
void * malloc_n(size_type, size_type);
void free_n(void *const, const size_type, const size_type);
void ordered_free_n(void *const, const size_type, const size_type);

// public static functions


static void * segregate(void *, size_type, size_type, void * = 0);
};

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).

simple_segregated_storage public construct/copy/destruct

1.
simple_segregated_storage(const simple_segregated_storage &);

2.
simple_segregated_storage();

Construct empty storage area.


Postconditions: empty()

42

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

3.
simple_segregated_storage& operator=(const simple_segregated_storage &);

simple_segregated_storage private static functions

1.
static void *
try_malloc_n(void *& start, size_type n, size_type partition_size);

Requires: (n > 0), (start != 0), (nextof(start) != 0)


Postconditions: (start != 0) The function attempts to find n contiguous chunks of size partition_size in the free list,
starting at start. If it succeds, it returns the last chunk in that contiguous sequence, so that the sequence
is known by [start, {retval}] If it fails, it does do either because it's at the end of the free list or hits a
non-contiguous chunk. In either case, it will return 0, and set start to the last considered chunk. You are
at the end of the free list if nextof(start) == 0. Otherwise, start points to the last chunk in the contiguous
sequence, and nextof(start) points to the first chunk in the next contiguous sequence (assuming an ordered
free list).

simple_segregated_storage protected member functions

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.

simple_segregated_storage protected static functions

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.

simple_segregated_storage public member functions

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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;

Returns: true only if simple_segregated_storage is empty.

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);

Free n chunks from order list.


Requires: chunks was previously allocated from *this with the same values for n and partition_size.

n should not be zero (n == 0 has no effect).

44

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

simple_segregated_storage public static functions

1.
static void *
segregate(void * block, size_type nsz, size_type npartition_sz,
void * end = 0);

Segregate block into chunks.


Requires: npartition_sz >= sizeof(void *)

npartition_sz = sizeof(void *) * i, for some integer i

nsz >= npartition_sz

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;
}

Class template singleton_pool


boost::singleton_pool

45

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Synopsis
// In header: <boost/pool/singleton_pool.hpp>

template<typename Tag, unsigned RequestedSize, typename UserAllocator,


typename Mutex, unsigned NextSize, unsigned MaxSize>
class singleton_pool {
public:
// types
typedef Tag tag;
typedef Mutex mutex; // The type of mutex used to ↵
synchonise access to this pool (default details::pool::default_mutex).
typedef UserAllocator user_allocator; // The user-allocator used ↵
by this pool, default = default_user_allocator_new_delete.
typedef pool< UserAllocator >::size_type size_type; // size_type of user allocator.
typedef pool< UserAllocator >::difference_type difference_type; // difference_type of user ↵
allocator.

// member classes/structs/unions

struct object_creator {
// construct/copy/destruct
object_creator();

// public member functions


void do_nothing() const;
};

// construct/copy/destruct
singleton_pool();

// public static functions


static void * malloc();
static void * ordered_malloc();
static void * ordered_malloc(const size_type);
static bool is_from(void *const);
static void free(void *const);
static void ordered_free(void *const);
static void free(void *const, const size_type);
static void ordered_free(void *const, const size_type);
static bool release_memory();
static bool purge_memory();

// private static functions


static pool_type & get_pool();

// public data members


static const unsigned requested_size; // The size of each chunk allocated by this pool.
static const unsigned next_size; // The number of chunks to allocate on the first allocation.
static pool< UserAllocator > p; // For exposition only!
};

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.

RequestedSize The size of each chunk returned by member function malloc().

UserAllocator User allocator, default = default_user_allocator_new_delete.

46

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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.

4 The underlying pool is constructed "as if" by:

pool<UserAllocator> p(RequestedSize, NextSize, MaxSize);

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.

singleton_pool public types

1. typedef Tag tag;

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.

singleton_pool public construct/copy/destruct

1.
singleton_pool();

singleton_pool public static functions

1.
static void * malloc();

Equivalent to SingletonPool::p.malloc(); synchronized.

47

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

2.
static void * ordered_malloc();

Equivalent to SingletonPool::p.ordered_malloc(); synchronized.

3.
static void * ordered_malloc(const size_type n);

Equivalent to SingletonPool::p.ordered_malloc(n); synchronized.

4.
static bool is_from(void *const ptr);

Equivalent to SingletonPool::p.is_from(chunk); synchronized.


Returns: true if chunk is from SingletonPool::is_from(chunk)

5.
static void free(void *const ptr);

Equivalent to SingletonPool::p.free(chunk); synchronized.

6.
static void ordered_free(void *const ptr);

Equivalent to SingletonPool::p.ordered_free(chunk); synchronized.

7.
static void free(void *const ptr, const size_type n);

Equivalent to SingletonPool::p.free(chunk, n); synchronized.

8.
static void ordered_free(void *const ptr, const size_type n);

Equivalent to SingletonPool::p.ordered_free(chunk, n); synchronized.

9.
static bool release_memory();

Equivalent to SingletonPool::p.release_memory(); synchronized.

10.
static bool purge_memory();

Equivalent to SingletonPool::p.purge_memory(); synchronized.

singleton_pool private static functions

1.
static pool_type & get_pool();

Struct object_creator
boost::singleton_pool::object_creator

48

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Synopsis
// In header: <boost/pool/singleton_pool.hpp>

struct object_creator {
// construct/copy/destruct
object_creator();

// public member functions


void do_nothing() const;
};

Description
object_creator public construct/copy/destruct

1.
object_creator();

object_creator public member functions

1.
void do_nothing() const;

49

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Appendices
Appendix A: History
Version 2.0.0, January 11, 2011
Documentation and testing revision

Features:

• Fix issues 1252, 4960, 5526, 5700, 2696.

• 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.

Choose add \boost-sandbox\boost_docs\trunk\doc\style\html\conversion\html_to_quickbook.css to My Style


Sheet. Html pages are now displayed as Quickbook and can be copied and pasted into quickbook files using your favored text editor
for Quickbook.

Version 1.0.0, January 1, 2000


First release

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.

When should I use Pool?

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Existing open tickets for this library alone can be viewed here. Existing tickets for this library - including closed ones - can be viewed
here.

Appendix F: Other Implementations


Pool allocators are found in many programming languages, and in many variations. The beginnings of many implementations may
be found in common programming literature; some of these are given below. Note that none of these are complete implementations
of a Pool; most of these leave some aspects of a Pool as a user exercise. However, in each case, even though some aspects are
missing, these examples use the same underlying concept of a Simple Segregated Storage described in this document.

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.

• Suffers from the static initialization problem.

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).

• Requires non-intuitive user code to create and destroy the Pool.

3. Efficient C++: Performance Programming Techniques, by Dov Bulka and David Mayhew, Chapters 6 and 7.

• This is a good example of iteratively developing a Pool solutio.

• 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.

• The static pooling example is not portable.

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Appendix H: Future plans


Another pool interface will be written: a base class for per-class pool allocation.

This "pool_base" interface will be Singleton Usage with Exceptions, and built on the singleton_pool interface.

52

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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
const_reference
Class template fast_pool_allocator, 37
Class template pool_allocator, 33
pool_allocator, 8

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Class template pool, 26


Class template simple_segregated_storage, 42
Guaranteeing Alignment - How we guarantee alignment portably., 13
Header < boost/pool/pool.hpp >, 25
How Contiguous Chunks are Handled, 15
pool, 4
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
allocation
Allocation and Deallocation, 16
Appendix B: FAQ, 50
Appendix F: Other Implementations, 51
Appendix G: References, 51
Appendix H: Future plans, 52
Basic ideas behind pooling, 10
Boost Pool Interfaces - What interfaces are provided and when to use each one., 3
Class template object_pool, 22, 24
Class template pool, 27, 29, 31
Class template simple_segregated_storage, 41
Class template singleton_pool, 46
Guaranteeing Alignment - How we guarantee alignment portably., 13
Header < boost/pool/object_pool.hpp >, 22
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_allocator, 8
Simple Segregated Storage, 12
Allocation and Deallocation
allocation, 16
block, 16
chunk, 16
deallocation, 16
malloc, 16
ordered, 16
size, 16
Appendix B: FAQ
allocation, 50
deallocation, 50
interface, 50
memory, 50
objects, 50
Appendix F: Other Implementations
allocation, 51
block, 51
concepts, 51
objects, 51
portable, 51
segregated, 51
Appendix G: References
allocation, 51
malloc, 51
memory, 51
segregated, 51

59

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Appendix H: Future plans


allocation, 52
interface, 52
singleton, 52
singleton_pool, 52
automatic
Class template object_pool, 22
Guaranteeing Alignment - How we guarantee alignment portably., 13
Header < boost/pool/object_pool.hpp >, 22
Object_pool, 6

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Class template pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>, 36


pool_allocator, 8
const_reference
Class template fast_pool_allocator, 37
Class template pool_allocator, 33
pool_allocator, 8
conventions
Documentation Naming and Formatting Conventions, 2

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Header < boost/pool/simple_segregated_storage.hpp >, 41


Header < boost/pool/singleton_pool.hpp >, 45
How do I use Pool?, 3
Installation, 3
Macro BOOST_POOL_VALIDATE_INTERNALS, 45
Struct default_user_allocator_malloc_free, 26
Struct default_user_allocator_new_delete, 25
Struct fast_pool_allocator_tag, 37
Struct object_creator, 49
Struct pool_allocator_tag, 32
Struct template rebind, 35, 36, 40, 41
How Contiguous Chunks are Handled
alignment, 15
allocation, 15
block, 15
chunk, 15
memory, 15
objects, 15
ordered, 15
padding, 15
size, 15
sizeof, 15
How do I use Pool?
headers, 3
include, 3
interface, 3

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

Class template pool, 27, 28, 29, 30


Class template pool_allocator, 33
Class template simple_segregated_storage, 42, 45
Class template singleton_pool, 46
Documentation Naming and Formatting Conventions, 2
Guaranteeing Alignment - How we guarantee alignment portably., 13, 14
Header < boost/pool/object_pool.hpp >, 22
Header < boost/pool/simple_segregated_storage.hpp >, 41
Header < boost/pool/singleton_pool.hpp >, 45
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_malloc_free, 26
Struct default_user_allocator_new_delete, 25
Struct object_creator, 48, 49
The UserAllocator Concept, 21
UserAllocator Requirements, 21
object_creator
Class template singleton_pool, 46
Struct object_creator, 49
Object_pool
allocation, 6
automatic, 6
chunk, 6
construct, 6
destroy, 6
difference_type, 6
element_type, 6
free, 6
interface, 6
is_from, 6
malloc, 6
memory, 6
objects, 6
object_pool, 6
size, 6
size_type, 6
template, 6
user_allocator, 6
object_pool
Class template object_pool, 22, 23
Header < boost/pool/object_pool.hpp >, 22
Object_pool, 6
Struct default_user_allocator_malloc_free, 26
ordered
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 pool, 27, 28, 29, 30, 31
Class template simple_segregated_storage, 42, 43, 44
Class template singleton_pool, 46, 48
Constructors, Destructors, and State, 16

71

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

How Contiguous Chunks are Handled, 15


pool, 4
pool_allocator, 8
Segregation, 16
Simple Segregated Storage (Not for the faint of heart - Embedded programmers only!), 16
Singleton_pool, 7
ordered_free
Class template pool, 27, 30, 31
Class template simple_segregated_storage, 42, 44
Class template singleton_pool, 46, 48
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
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
overview
Guaranteeing Alignment - How we guarantee alignment portably., 13
Introduction and Overview, 2

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/


Boost.Pool

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

XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/

You might also like