Project: ArangoDB (App Definition and Development / Database)
File: pool.pdf

Boost.P ool
Stephen Clear y
Copyright © 2000-2006 Stephen Clear y
Copyright © 2011 P aul A.  Bristow
Distrib uted under the Boost Softw are License, Version 1.0. (See accompan ying file LICENSE_1_0.txt or cop y at
http://www .boost.or g/LICENSE_1_0.txt )
Table of Contents
Introduction and Ov ervie w.......................................................................................................................................2
Documentation Naming and F ormatting Con ventions ............................................................................................2
Introduction ..................................................................................................................................................2
How do I use Pool? ........................................................................................................................................3
Installation ....................................................................................................................................................3
Building the Test Programs ..............................................................................................................................3
Boost Pool Interf aces - What interf aces are pro vided 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_se gregated_storage.hpp> ..........................................................................................41
Header <boost/pool/singleton_pool.hpp> ..........................................................................................................45
Appendices .........................................................................................................................................................50
Appendix A: History .....................................................................................................................................50
Appendix B: F AQ.........................................................................................................................................50
Appendix C: Ackno wledgements .....................................................................................................................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
1
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Introduction and Over view
Documentation Naming and Formatting Con ventions
This documentation mak es use of the follo wing naming and formatting con ventions.
•Code is in fixedwidthfont  and is syntax-highlighted in color .
•Replaceable te xt that you will need to supply is in italics .
•Free functions are rendered in the codefont  follo wed by (), as in free_function ().
•If a name refers to a class template, it is specified lik e this: class_template <>; that is, it is in code font and its name is follo wed
by <> to indicate that it is a class template.
•If a name refers to a function-lik e macro, it is specified lik e this: MACRO(); that is, it is uppercase in code font and its name is
followed by () to indicate that it is a function-lik e macro. Object-lik e 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 pro vides additional background or rationale.
Finally , you can mentally add the follo wing to an y code fragments in this document:
// Include all of Pool files
#include <boost/pool.hpp>
Introduction
What is P ool?
Pool allocation is a memory allocation scheme that is v ery f ast, b ut limited in its usage. F or more information on pool allocation
(also called simple se gregated stor age, see concepts  concepts and Simple Se gregated Storage ).
Why should I use P ool?
Using Pools gi ves you more control o ver ho w memory is used in your program. F or example, you could ha ve a situation where you
want to allocate a b unch of small objects at one point, and then reach a point in your program where none of them are needed an y
more. Using pool interf aces, you can choose to run their destructors or just drop them of f into obli vion; the pool interf ace will
guarantee that there are no system memory leaks.
When should I use P ool?
Pools are generally used when there is a lot of allocation and deallocation of small objects. Another common usage is the situation
above, where man y objects may be dropped out of memory .
In general, use Pools when you need a more efficient w ay to do unusual memory control.
Whic h pool allocator should I use?
pool_allocator  is a more general-purpose solution, geared to wards efficiently servicing requests for an y number of contiguous
chunks.
fast_pool_allocator  is also a general-purpose solution b ut is geared to wards efficiently servicing requests for one chunk at a
time; it will w ork for contiguous chunks, b ut not as well as pool_allocator .
2Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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 P ool?
See the Pool Interf aces section that co vers the dif ferent Pool interf aces supplied by this library .
Librar y Structure and Dependencies
Forward declarations of all the e xposed symbols for this library are in the header made inscope by #include
<boost/pool/poolfwd.hpp>.
The library may use macros, which will be prefix ed with BOOST_POOL_ . The e xception to this rule are the include file guards, which
(for file xxx.hpp) is BOOST_xxx_HPP .
All e xposed 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 an y other header in the library or an y 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 b uild; just add the Boost directory to your
compiler's include file path, and you should be good to go!
Building the Test Pr ograms
A jamfile.v2 is pro vided which can be run is the usual w ay, for e xample:
boost\libs\pool\test>bjam-a>pool_test .log
Boost P ool Interfaces - What interfaces are pr ovided and when
to use eac h one .
Introduction
There are se veral interf aces pro vided which allo w users great fle xibility in ho w the y want to use Pools. Re view the concepts  document
to get the basic understanding of ho w the v arious pools w ork.
Terminology and Tradeoffs
Object Usa ge vs.  Singleton Usa ge
Object Usage is the method where each Pool is an object that may be created and destro yed. Destro ying a Pool implicitly frees all
chunks that ha ve been allocated from it.
Singleton Usage is the method where each Pool is an object with static duration; that is, it will not be destro yed until program e xit.
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 pur ge_memory .
Out-of-Memor y Conditions:  Exceptions vs.  Null Return
Some Pool interf aces thro w exceptions when out-of-memory; others will return0. In general, unless mandated by the Standard,
Pool interf aces will al ways prefer to return0 instead of thro wing an e xception.
3Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Ordered ver sus unor dered
An ordered pool maintains it's free list in order of the address of each free block - this is the most efficient w ay if you're lik ely to
allocate arrays of objects. Ho wever, freeing an object can be O(N) in the number of currently free blocks which can be prohibiti vely
expensi ve in some situations.
An unordered pool does not maintain it's free list in an y particular order , as a result allocation and freeing single objects is v ery fast,
but allocating arrays may be slo w (and in particular the pool may not be a ware that it contains enough free memory for the allocation
request, and unnecessarily allocate more memory).
Pool Interfaces
pool
The pool  interf ace is a simple Object Usage interf ace with Null Return.
pool  is a f ast memory allocator , and guarantees proper alignment of all allocated chunks.
pool.hpp  provides tw o UserAllocator  classes and a template class pool , which e xtends and generalizes the frame work
provided by the Simple Se gregated Storage  solution. F or information on other pool-based interf aces, see the other Pool Interf aces.
Synopsis
There are tw o UserAllocator  classes pro vided. Both of them are in pool.hpp .
The def ault v alue for the template parameter UserAllocator  is al ways default_user_allocator_new_delete .
4Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/structdefault_user_allocator_new_delete
{
typedef std::size_tsize_type ;
typedef std::ptrdiff_t difference_type ;
staticchar*malloc(constsize_type bytes)
{returnnew(std::nothrow)char[bytes];}
staticvoidfree(char*constblock)
{delete[]block;}
};
structdefault_user_allocator_malloc_free
{
typedef std::size_tsize_type ;
typedef std::ptrdiff_t difference_type ;
staticchar*malloc(constsize_type bytes)
{returnreinterpret_cast <char*>(std::malloc(bytes));}
staticvoidfree(char*constblock)
{std::free(block);}
};
template <typename UserAllocator =default_user_allocator_new_delete >
classpool
{
private:
pool(constpool&);
voidoperator =(constpool&);
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();
boolrelease_memory ();
boolpurge_memory ();
boolis_from(void*chunk)const;
size_type get_requested_size ()const;
void*malloc();
void*ordered_malloc ();
void*ordered_malloc (size_type n);
voidfree(void*chunk);
voidordered_free (void*chunk);
voidfree(void*chunks,size_type n);
voidordered_free (void*chunks,size_type n);
};
Example:
5Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/voidfunc()
{
boost::pool<>p(sizeof(int));
for(inti=0;i<10000;++i)
{
int*constt=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  interf ace is an Object Usage interf ace with Null Return, b ut is a ware of the type of the object
for which it is allocating chunks. On destruction, an y chunks that ha ve been allocated from that object_pool  will ha ve their de-
structors called.
object_pool.hpp  provides a template type that can be used for f ast and efficient memory allocation. It also pro vides automatic
destruction of non-deallocated objects.
For information on other pool-based interf aces, see the other Pool Interf aces.
Synopsis
template <typename ElementType ,typename UserAllocator =default_user_allocator_new_delete >
classobject_pool
{
private:
object_pool (constobject_pool &);
voidoperator =(constobject_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();
voidfree(element_type *p);
boolis_from(element_type *p)const;
element_type *construct ();
// other construct() functions
voiddestroy(element_type *p);
};
Template P arameters
ElementT ype
The template parameter is the type of object to allocate/deallocate. It must ha ve a non-thro wing destructor .
UserAllocator
Defines the method that the underlying Pool will use to allocate memory from the system. Def ault is def ault_user_allocator_ne w_delete.
See __ UserAllocator  for details.
Example:  struct X { ... }; // has destructor with side-ef fects.
6Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/voidfunc()
{
boost::object_pool <X>p;
for(inti=0;i<10000;++i)
{
X*constt=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 interf ace with Null Return. It's just the same
as the pool interf ace b ut with Singleton Usage instead.
Synopsis
template <typename Tag,unsigned RequestedSize ,
typename UserAllocator =default_user_allocator_new_delete >
structsingleton_pool
{
public:
typedef Tagtag;
typedef UserAllocator user_allocator ;
typedef typename pool<UserAllocator >::size_type size_type ;
typedef typename pool<UserAllocator >::difference_type difference_type ;
staticconstunsigned requested_size =RequestedSize ;
private:
staticpool<size_type >p;// exposition only!
singleton_pool ();
public:
staticboolis_from(void*ptr);
staticvoid*malloc();
staticvoid*ordered_malloc ();
staticvoid*ordered_malloc (size_type n);
staticvoidfree(void*ptr);
staticvoidordered_free (void*ptr);
staticvoidfree(void*ptr,std::size_tn);
staticvoidordered_free (void*ptr,size_type n);
staticboolrelease_memory ();
staticboolpurge_memory ();
};
Notes
The underlying pool p referenced by the static functions in singleton_pool  is actually declared in a w ay 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 abo ve would actually be an incorrect
implementation. The actual implementation to guarantee this is considerably more complicated.
Note  that a dif ferent underlying pool p exists for each dif ferent set of template parameters, including implementation-specific ones.
7Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Template P arameters
Tag
The Tag template parameter allo ws dif ferent unbounded sets of singleton pools to e xist. F or example, the pool allocators use tw o
tag classes to ensure that the tw o different allocator types ne ver share the same underlying singleton pool.
Tag is ne ver 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 MyPoolT ag { };
typedef boost::singleton_pool <MyPoolTag ,sizeof(int)>my_pool;
voidfunc()
{
for(inti=0;i<10000;++i)
{
int*constt=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 interf ace with Exceptions. It is b uilt on the singleton_pool interf ace, and
provides a Standard Allocator -compliant class (for use in containers, etc.).
Introduction
pool_alloc.hpp
Provides tw o template types that can be used for f ast 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 the y can be used with Standard or user -supplied containers.
For information on other pool-based interf aces, see the other Pool Interf aces.
Synopsis
8Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/structpool_allocator_tag {};
template <typename T,
typename UserAllocator =default_user_allocator_new_delete >
classpool_allocator
{
public:
typedef UserAllocator user_allocator ;
typedef Tvalue_type ;
typedef value_type *pointer;
typedef constvalue_type *const_pointer ;
typedef value_type &reference ;
typedef constvalue_type &const_reference ;
typedef typename pool<UserAllocator >::size_type size_type ;
typedef typename pool<UserAllcoator >::difference_type difference_type ;
template <typename U>
structrebind
{typedef pool_allocator <U,UserAllocator >other;};
public:
pool_allocator ();
pool_allocator (constpool_allocator &);
// The following is not explicit, mimicking std::allocator [20.4.1]
template <typename U>
pool_allocator (constpool_allocator <U,UserAllocator >&);
pool_allocator &operator =(constpool_allocator &);
~pool_allocator ();
staticpointer address(reference r);
staticconst_pointer address(const_reference s);
staticsize_type max_size ();
staticvoidconstruct (pointer ptr,constvalue_type &t);
staticvoiddestroy(pointer ptr);
booloperator ==(constpool_allocator &)const;
booloperator !=(constpool_allocator &)const;
staticpointer allocate (size_type n);
staticpointer allocate (size_type n,pointer);
staticvoiddeallocate (pointer ptr,size_type n);
};
structfast_pool_allocator_tag {};
template <typename T
typename UserAllocator =default_user_allocator_new_delete >
classfast_pool_allocator
{
public:
typedef UserAllocator user_allocator ;
typedef Tvalue_type ;
typedef value_type *pointer;
typedef constvalue_type *const_pointer ;
typedef value_type &reference ;
typedef constvalue_type &const_reference ;
typedef typename pool<UserAllocator >::size_type size_type ;
typedef typename pool<UserAllocator >::difference_type difference_type ;
template <typename U>
structrebind
{typedef fast_pool_allocator <U,UserAllocator >other;};
9Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/public:
fast_pool_allocator ();
fast_pool_allocator (constfast_pool_allocator &);
// The following is not explicit, mimicking std::allocator [20.4.1]
template <typename U>
fast_pool_allocator (constfast_pool_allocator <U,UserAllocator >&);
fast_pool_allocator &operator =(constfast_pool_allocator &);
~fast_pool_allocator ();
staticpointer address(reference r);
staticconst_pointer address(const_reference s);
staticsize_type max_size ();
staticvoidconstruct (pointer ptr,constvalue_type &t);
staticvoiddestroy(pointer ptr);
booloperator ==(constfast_pool_allocator &)const;
booloperator !=(constfast_pool_allocator &)const;
staticpointer allocate (size_type n);
staticpointer allocate (size_type n,pointer);
staticvoiddeallocate (pointer ptr,size_type n);
staticpointer allocate ();
staticvoiddeallocate (pointer ptr);
};
Template P arameters
TThe 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:
voidfunc()
{
std::vector<int,boost::pool_allocator <int>>v;
for(inti=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 r oughly 1960... 1
Everyone uses dynamic memory allocation. If you ha ve ever called malloc or ne w, then you ha ve used dynamic memory allocation.
Most programmers ha ve a tendenc y 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. Ev en on lar ge systems (i.e., not embedded) with huge amounts of virtual memory a vailable, there is a limit.
Everyone is a ware of the ph ysical limit, b ut there is a more subtle, 'virtual' limit, that limit at which your program (or the entire system)
slows do wn due to the use of virtual memory . This virtual limit is much closer to your program than the ph ysical limit, especially
if you are running on a multitasking system. Therefore, when running on a lar ge system, it is considered nice to mak e your program
10Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/use as fe w resources as necessary , and release them as soon as possible. When using an embedded system, programmers usually
have no memory to w aste.
The heap is complicated. It has to satisfy an y type of memory request, for an y size, and do it f ast. The common approaches to memory
management ha ve to do with splitting the memory up into portions, and k eeping them ordered by size in some sort of a tree or list
structure. Add in other f actors, such as locality and estimating lifetime, and heaps quickly become v ery complicated. So complicated,
in fact, that there is no kno wn perfect  answer to the problem of ho w to do dynamic memory allocation. The diagrams belo w illustrate
how most common memory managers w ork: for each chunk of memory , it uses part of that memory to maintain its internal tree or
list structure. Ev en 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 ho w lar ge it is.
Dynamic memor y 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 tak e up one machine w ord in a block that
is being used by the program. The ob vious disadv antage, then, is when small objects are dynamically allocated. F or example, if ints
were dynamically allocated, then automatically the algorithm will reserv e space for the header fields as well, and we end up with a
50% w aste of memory . Of course, this is a w orst-case scenario. Ho wever, 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 a verage-case memory o verhead is
about ten to twenty percent 2. This memory o verhead will gro w higher as more programs use more smaller objects. It is this memory
overhead that brings programs closer to the virtual limit.
In lar ger systems, the memory o verhead is not as big of a problem (compared to the amount of time it w ould tak e to w ork around
it), and thus is often ignored. Ho wever, there are situations where man y 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 slo w.
Simple se gregated storage addresses both of these issues. Almost all memory o verhead is done a way with, and all allocations can
take place in a small amount of (amortized) constant time. Ho wever, this is done at the loss of generality; simple se gregated storage
only can allocate memory chunks of a single size.
11Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Simple Segregated Stora ge
Simple Se gregated 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 be gins by partitioning a memory block into fix ed-size chunks. Where the
block comes from is not important until implementation time. A Pool is some object that uses Simple Se gregated Storage in this
fashion. To illustrate:
Each of the chunks in an y given block are al ways the same size. This is the fundamental restriction of Simple Se gregated Storage:
you cannot ask for chunks of dif ferent sizes. F or example, you cannot ask a Pool of inte gers for a character , or a Pool of characters
for an inte ger (assuming that characters and inte gers are dif ferent sizes).
Simple Se gregated Storage w orks by interlea ving a free list within the unused chunks. F or example:
By interlea ving the free list inside the chunks, each Simple Se gregated Storage only has the o verhead of a single pointer (the pointer
to the first element in the list). It has no memory o verhead for chunks that are in use by the process.
Simple Se gregated Storage is also e xtremely f ast. In the simplest case, memory allocation is merely remo ving the first chunk from
the free list, a O(1) operation. In the case where the free list is empty , another block may ha ve 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. Ho wever, more complicated uses of Simple Se gregated Storage may require a sorted free list, which mak es dealloc-
ation O(N).
12Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Simple Se gregated Storage gi ves faster e xecution and less memory o verhead than a system-supplied allocator , but at the loss of
generality . A good place to use a Pool is in situations where man y (noncontiguous) small objects may be allocated on the heap, or
if allocation and deallocation of the same-sized objects happens repeatedly .
Guaranteeing Alignment - Ho w we guarantee alignment por tably.
Terminology
Review the concepts  section if you are not already f amiliar with it. Remember that block is a contiguous section of memory , which
is partitioned or se gregated into fix ed-size chunks. These chunks are what are allocated and deallocated by the user .
Over view
Each Pool has a single free list that can e xtend o ver a number of memory blocks. Thus, Pool also has a link ed list of allocated memory
blocks. Each memory block, by def ault, is allocated using new[], and all memory blocks are freed on destruction. It is the use of
new[] that allo ws 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:  Arra ys ma y not ha ve pad ding
This follo ws from the follo wing quote:
[5.3.3/2] (Expressions::Unary e xpressions::Sizeof) ... When applied to an arr ay, the r esult is the total number of bytes in the arr ay.
This implies that the size of an arr ay 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 memor y allocated as an arra y of c haracter s through operator new[] (hereafter ref erred
to as the b lock) is pr operl y aligned f or an y object of that siz e or smaller
This follo ws from:
•[3.7.3.1/2] (Basic concepts::Storage duration::Dynamic storage duration::Allocation functions) "... The pointer r eturned shall be
suitably aligned so that it can be con verted to a pointer of any complete object type and then used to access the object or arr ay
in the stor age allocated ..."
•[5.3.4/10] (Expressions::Unary e xpressions::Ne w) "... F or arr ays of c har and unsigned c har, the dif ference between the r esult of
the ne w-expression and the addr ess returned by the allocation function shall be an inte gral multiple of the most string ent alignment
13Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/requir ement (3.9) of any object type whose size is no gr eater than the size of the arr ay being cr eated. [Note: Because allocation
functions ar e assumed to r eturn pointer s to stor age that is appr opriately aligned for objects of any type , this constr aint on arr ay
allocation o verhead permits the common idiom of allocating c haracter arr ays into whic h objects of other types will later be
placed."
Consider:  imaginar y object type Element of a siz e whic h is a m ultiple of some actual object siz e; assume
sizeof (Element )>POD_size
Note that an object of that size can e xist. One object of that size is an array of the "actual" objects.
Note that the block is properly aligned for an Element. This directly follo ws from Predicate 2.
Corollar y 1:The b lock is pr operl y aligned f or an arra y of Elements
This follo ws from Predicates 1 and 2, and the follo wing quote:
[3.9/9] (Basic concepts::T ypes) "An object type is a (possibly cv-qualified) type that is not a function type , not a r eference type , and
not a void type ."
(Specifically , array types are object types.)
Corollar y 2: For an y pointer p and integ er i, if p is pr operl y aligned f or the type it points to,  then p+i (when
well-defined) is pr operl y aligned f or that type;  in other w ords, if an arra y is pr operl y aligned,  then eac h element
in that arra y is pr operl y aligned
There are no quotes from the Standard to directly support this ar gument, b ut 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, b ut only mak e 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 m ultiple of siz es of se veral actual objects (T1, T2,T3, ...)
Let: block be a pointer to the memor y block, pe be (Element *) b lock, and pn be (Tn *) b lock
Corollar y 3: For eac h integ er i, such that pe+i is well-defined,  then f or eac h n, there e xists some integ er jn
such that pn+jn is well-defined and ref ers to the same memor y address as pe+i
This follo ws 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 eac h integ er i, such that pe+i is well-defined,  that ad dress (pe + i) is pr operl y aligned f or eac h
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 abo ve 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 v oid); this is because we interlea ve our free list through the chunks
•size_type ; this is because we store the size of the ne xt block within each memory block
Each block also contains a pointer to the ne xt block; b ut that is stored as a pointer to v oid and cast when necessary , to simplify
alignment requirements to the three types abo ve.
14Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Therefore, alloc_size  is defined to be the lar gest of the sizes abo ve, rounded up to be a multiple of all three sizes. This guarantees
alignment pro vided all alignments are po wers of tw o: something that appears to be true on all kno wn platforms.
A Look at the Memor y Bloc k
Each memory block consists of three main sections. The first section is the part that chunks are cut out of, and contains the interlea ved
free list. The second section is the pointer to the ne xt block, and the third section is the size of the ne xt block.
Each of these sections may contain padding as necessary to guarantee alignment for each of the ne xt 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 e xample memory block, where requested_size ==sizeof(void*)==sizeof(size_type )==4:
To sho w a visual e xample of possible padding, here's an e xample memory block where requested_size ==8andsizeof(void
*)==sizeof(size_type )==4
How Contiguous Chunks are Handled
The theorem abo ve guarantees all alignment requirements for allocating chunks and also implementation details such as the interlea ved
free list. Ho wever, it does so by adding padding when necessary; therefore, we ha ve to treat allocations of contiguous chunks in a
different w ay.
Using array ar guments similar to the abo ve, we can translate an y 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:
15Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Here's an e xample 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 ag ain.
Note that the implementation pro vided 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 al ways use an ordered free list
when dealing with contiguous allocation of chunks. (In the e xample abo ve, if Chunk 1 pointed to Chunk 3 pointed to Chunk 2
pointed to Chunk 4, instead of being in order , the contiguous allocation algorithm w ould ha ve failed to find an y of the contiguous
chunks).
Simple Segregated Stora ge (Not f or the faint of hear t - Embed ded pr ogrammer s
only!)
Introduction
simple_segregated_storage.hpp  provides a template class simple_se gregated_storage that controls access to a free list of
memory chunks.
Note that this is a v ery simple class, with uncheck ed preconditions on almost all its functions. It is intended to be the f astest and
smallest possible quick memory allocator for e xample, something to use in embedded systems. This class dele gates man y difficult
preconditions to the user (especially alignment issues). F or more general usage, see the other Pool Interf aces.
16Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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 v alues,
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
Meaning Symbol
simple_se gregated_storage<SizeT ype> Store
value of type Store t
value of type const Store u
values of type v oid * block, chunk, end
values of type Store::size_type partition_sz, sz, n
17Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Table 2. Template P arameters
Requir ements Default Parameter
An unsigned inte gral type std::size_t SizeT ype
Table 3. Typedefs
Type Symbol
SizeT ype size_type
Table 4. Constructors, Destructors, and State
Notes Post-Condition Retur n Type Expr ession
Constructs a ne w Store empty() not used Store()
Destructs the Store not used (&t)->~Store()
Returns true if u is empty . Or-
der-preserving.bool u.empty()
18Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Table 5. Segr egation
Notes Semantic Equi val-
encePost-Condition Pre-Condition Retur n Type Expr ession
Interlea ves a free
list through the
memory block spe-
cified by block of
size sz bytes, parti-
tioning it into as
many partition_sz-
sized chunks as
possible. The last
chunk is set to
point to end, and a
pointer to the first
chunck is returned
(this is al ways
equal to block).
This interlea ved
free list is ordered.
O(sz).partition_sz >=
sizeof(v oid *) parti-
tion_sz =
sizeof(v oid *) * i,
for some inte ger i
sz >= partition_sz
block is properly
aligned for an array
of objects of size
partition_sz block
is properly aligned
for an array of v oid
*void * Store::se greg-
ate(block, sz, parti-
tion_sz, end)
Store::se greg-
ate(block, sz, parti-
tion_sz, 0)Same as abo ve void * Store::se greg-
ate(block, sz, parti-
tion_sz)
Segregates the
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 w as
empty before this
call, then it is
ordered after this
call. O(sz).!t.empty() Same as abo ve void t.add_block(block,
sz, partition_sz)
Segregates the
memory block spe-
cified by block of
size sz bytes into
partition_sz-sized
chunks, and mer ges
that free list into its
own. Order -pre-
serving. O(sz).!t.empty() Same as abo ve void t.add_ordered_block(block,
sz, partition_sz)
19Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Table 6. Allocation and Deallocation
Notes Semantic Equi val-
encePost-Condition Pre-Condition Retur n Type Expr ession
Takes the first
available chunk!t.empty() void * t.malloc()
from the free list
and returns it. Or -
der-preserving.
O(1).
Places chunk back
on the free list.!t.empty() chunk w as pre vi-
ously returnedvoid t.free(chunk)
Note that chunk
may not be 0. O(1).from a call to
t.malloc()
Places chunk back
on the free list.!t.empty() Same as abo ve void t.ordered_free(chunk)
Note that chunk
may not be 0. Or -
der-preserving.
O(N) with respect
to the size of the
free list.
Attempts to find a
contiguous se-void * t.malloc_n(n, parti-
tion_sz)
quence of n parti-
tion_sz-sized
chunks. If found,
remo ves them all
from the free list
and returns a point-
er to the first. If not
found, returns 0. It
is strongly recom-
mended (b ut 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.
20Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Notes Semantic Equi val-
encePost-Condition Pre-Condition Retur n Type Expr ession
Assumes that
chunk actually
refers to a block of
chunks spanning n
* partition_sz
bytes; se gregates
and adds in that
block. Note that
chunk may not be
0. O(n).t.add_block(chunk,
n * partition_sz,
partition_sz)!t.empty() chunk w as pre vi-
ously returned
from a call to
t.malloc_n(n, parti-
tion_sz)void t.free_n(chunk, n,
partition_sz)
Same as abo ve, ex-
cept it mer ges in
the free list. Order -
preserving. O(N +
n) where N is the
size of the free list.t.add_ordered_block(chunk,
n * partition_sz,
partition_sz)same as abo ve same as abo ve void t.ordered_free_n(chunk,
n, partition_sz)
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 v arious Pool interf aces, users can control ho w those system memory blocks are allocated.
In the follo wing table, UserAllocator  is a User Allocator type, block is a v alue of type char *, and n is a v alue of type UserAllocat-
or::size_type
Table 7. UserAllocator Requir ements
Description Result Expr ession
An unsigned inte gral type that can repres-
ent the size of the lar gest object to be al-
located.UserAllocator::size_type
A signed inte gral type that can represent
the dif ference of an y two pointers.UserAllocator::dif ference_type
Attempts to allocate n bytes from the
system. Returns 0 if out-of-memory .char * UserAllocator::malloc(n)
block must ha ve been pre viously returned
from a call to UserAllocator::malloc.void UserAllocator::free(block)
There are tw o UserAllocator classes pro vided in this library: default_user_allocator_new_delete  and default_user_al-
locator_malloc_free , both in pool.hpp. The def ault v alue for the template parameter UserAllocator is al ways default_user_al-
locator_new_delete .
21Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Boost.P ool C++ Ref erence
Header < boost/pool/object_pool.hpp >
Provides a template type boost::object_pool<T , UserAllocator> that can be used for f ast and efficient memory allocation of objects
of type T. It also pro vides automatic destruction of non-deallocated objects.
namespace boost{
template <typename  T,typename  UserAllocator >classobject_pool ;
}
Class template object_pool
boost::object_pool —A template class that can be used for f ast and efficient memory allocation of objects. It also pro vides automatic
destruction of non-deallocated objects.
Synopsis
// In header: < boost/pool/object_pool.hpp >
template <typename  T,typename  UserAllocator >
classobject_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 (constsize_type =32,constsize_type =0);
~object_pool ();
// protected member functions
pool<UserAllocator >&store();
constpool<UserAllocator >&store()const;
// protected static functions
staticvoid*&nextof(void*const);
// public member functions
element_type *malloc();
voidfree(element_type *const);
boolis_from(element_type *const)const;
element_type *construct ();
template <typename  Arg1,...class ArgN>
element_type *construct (Arg1&,...ArgN&);
voiddestroy(element_type *const);
size_type get_next_size ()const;
voidset_next_size (constsize_type );
};
Description
TThe type of object to allocate/deallocate. T must ha ve a non-thro wing destructor .
22Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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 f ast and efficient memory allocation of objects. It also pro vides automatic
destruction of non-deallocated objects.
When the object pool is destro yed, then the destructor for type T is called for each allocated T that has not yet been deallocated.
O(N).
Whene ver 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  pub lic construct/cop y/destruct
1.explicit object_pool (constsize_type  arg_next_size =32,
constsize_type  arg_max_size =0);
Constructs a ne w (empty by def ault) 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.constpool<UserAllocator >&store()const;
Returns: The underlying boost:: pool storage used by *this.
object_pool  protected static functions
1.staticvoid*&nextof(void*const ptr);
Returns: The ne xt memory block after ptr (for the sak e of code readability :)
object_pool  pub lic member functions
1.element_type *malloc();
Allocates memory that can hold one object of type ElementT ype.
If out of memory , returns 0.
Amortized O(1).
2.voidfree(element_type *const chunk);
De-Allocates memory that holds a chunk of type ElementT ype.
23Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Note that p may not be 0.
Note that the destructor for p is not called. O(N).
3.boolis_from(element_type *const chunk)const;
Returns f alse if chunk w as allocated from some other pool or may be returned as the result of a future allocation from some other
pool.
Otherwise, the return v alue is meaningless.
Note
This function may NO T be used to reliably test random pointer v alues!
Returns: true if chunk w as 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 def ault constructed. The returned
objected can be freed by a call to destro y. Otherwise the returned object will be automatically destro yed when *this
is destro yed.
5.template <typename  Arg1,...class ArgN>
element_type *construct (Arg1&,...ArgN&);
Note
Since the number and type of ar guments 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 a vailable 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 ar guments. The number of ar guments may be passed into the
file as an m4 macro, NumberOfAr guments; if not pro vided, it will def ault to 3.
For each dif ferent number of ar guments (1 to NumberOfAr guments), a template function is generated. There are
the same number of template parameters as there are ar guments, and each ar gument's type is a reference to that
(possibly cv-qualified) template ar gument. Each possible permutation of the cv-qualifications is also generated.
Because each permutation is generated for each possible number of ar guments, the included file size gro ws ex-
ponentially in terms of the number of constructor ar guments, not linearly . For the sak e of rational compile times,
only use as man y arguments as you need.
detail/pool_construct.bat and detail/pool_construct.sh are also pro vided to call m4, defining NumberOfAr guments
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 ar guments
Arg1 to ArgN. The returned objected can be freed by a call to destro y. Otherwise the returned object will be auto-
matically destro yed when *this is destro yed.
6.voiddestroy(element_type *const chunk);
Destro ys an object allocated with construct.
Equivalent to:
p->~ElementT ype(); this->free(p);
24Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Requires: p must ha ve been pre viously allocated from *this via a call to construct.
7.size_type get_next_size ()const;
Returns: The number of chunks that will be allocated ne xt time we run out of memory .
8.voidset_next_size (constsize_type  x);
Set a ne w number of chunks to allocate the ne xt time we run out of memory .
Parameters: xwanted ne xt_size (must not be zero).
Header < boost/pool/pool.hpp >
Provides class pool: a f ast memory allocator that guarantees proper alignment of all allocated chunks, and which e xtends and gener -
alizes the frame work pro vided by the simple se gregated storage solution. Also pro vides tw o UserAllocator classes which can be
used in conjuction with pool.
namespace boost{
structdefault_user_allocator_new_delete ;
structdefault_user_allocator_malloc_free ;
template <typename  UserAllocator >classpool;
}
Struct default_user_allocator_ne w_delete
boost::def ault_user_allocator_ne w_delete —Allocator used as the def ault template parameter for a UserAllocator  template parameter .
Uses ne w and delete.
Synopsis
// In header: < boost/pool/pool.hpp >
structdefault_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
staticchar*malloc(constsize_type );
staticvoidfree(char*const);
};
Description
default_user_allocator_new_delete  pub lic static functions
1.staticchar*malloc(constsize_type  bytes);
Attempts to allocate n bytes from the system. Returns 0 if out-of-memory
25Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/2.staticvoidfree(char*const block);
Attempts to de-allocate block.
Requires: Block must ha ve been pre viously returned from a call to UserAllocator::malloc.
Struct default_user_allocator_malloc_free
boost::def ault_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 >
structdefault_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
staticchar*malloc(constsize_type );
staticvoidfree(char*const);
};
Description
default_user_allocator_malloc_free  pub lic static functions
1.staticchar*malloc(constsize_type  bytes);
2.staticvoidfree(char*const block);
Class template pool
boost::pool —A fast memory allocator that guarantees proper alignment of all allocated chunks.
26Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Synopsis
// In header: < boost/pool/pool.hpp >
template <typename  UserAllocator >
classpool:
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(constsize_type ,constsize_type =32,constsize_type =0);
~pool();
// private member functions
void*malloc_need_resize ();
void*ordered_malloc_need_resize ();
// protected member functions
simple_segregated_storage <size_type >&store();
constsimple_segregated_storage <size_type >&store()const;
  details::PODptr <size_type >find_POD (void*const)const;
size_type alloc_size ()const;
// protected static functions
staticboolis_from(void*const,char*const,constsize_type );
staticvoid*&nextof(void*const);
// public member functions
boolrelease_memory ();
boolpurge_memory ();
size_type get_next_size ()const;
voidset_next_size (constsize_type );
size_type get_max_size ()const;
voidset_max_size (constsize_type );
size_type get_requested_size ()const;
void*malloc();
void*ordered_malloc ();
void*ordered_malloc (size_type );
voidfree(void*const);
voidordered_free (void*const);
voidfree(void*const,constsize_type );
voidordered_free (void*const,constsize_type );
boolis_from(void*const)const;
};
Description
Whene ver 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 follo wing e xtensions:
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 def ault is 32. This parameter may not be 0.
27Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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 tak es the def ault v alue 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 ag ain.
UserAllocator type  - the method that the Pool will use to allocate memory from the system.
There are essentially tw o 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 w ay to use a pool, b ut does not allo w for the efficient allocation of arrays of chunks. Alternati vely, 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. Ho wever, this latter option can suf fer from poor performance when lar ge numbers of allocations
are performed.
pool  pub lic construct/cop y/destruct
1.explicit pool(constsize_type  nrequested_size ,
constsize_type  nnext_size =32,constsize_type  nmax_size =0);
Constructs a ne w 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 def ault 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  priv ate member functions
1.void*malloc_need_resize ();
No memory in an y of our storages; mak e a ne w storage, Allocates chunk in ne wly 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 an y of our storages; mak e a ne w storage,
Returns: pointer to ne w chunk.
pool  protected member functions
1.simple_segregated_storage <size_type >&store();
Returns: pointer to store.
2.constsimple_segregated_storage <size_type >&store()const;
Returns: pointer to store.
28Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/3.details::PODptr <size_type >find_POD (void*const chunk)const;
finds which POD in the list 'chunk' w as 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.staticboolis_from(void*const chunk,char*const i,
constsize_type  sizeof_i );
Returns f alse if chunk w as allocated from some other pool, or may be returned as the result of a future allocation from some
other pool. Otherwise, the return v alue is meaningless.
Note that this function may not be used to reliably test random pointer v alues.
Parameters: chunk to check if is from this pool. chunk
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 w as allocated or may be returned. as the result of a future allocation.
2.staticvoid*&nextof(void*const ptr);
Returns: Pointer dereferenced. (Pro vided and used for the sak e of code readability :)
pool  pub lic member functions
1.boolrelease_memory ();
pool must be ordered. Frees e very memory block that doesn't ha ve any allocated chunks.
Returns: true if at least one memory block w as freed.
2.boolpurge_memory ();
pool must be ordered. Frees e very memory block.
This function in validates an y pointers pre viously returned by allocation functions of t.
Returns: true if at least one memory block w as freed.
3.size_type get_next_size ()const;
Number of chunks to request from the system the ne xt time that object needs to allocate system memory . This v alue should ne ver
be 0.
Returns: next_size;
4.voidset_next_size (constsize_type  nnext_size );
Set number of chunks to request from the system the ne xt time that object needs to allocate system memory . This v alue should
never be set to 0.
29Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Returns: nnext_size.
5.size_type get_max_size ()const;
Returns: max_size.
6.voidset_max_size (constsize_type  nmax_size );
Set max_size.
7.size_type get_requested_size ()const;
Returns: the requested size passed into the constructor . (This v alue 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 ne w memory block, adds its free list to pool's free list,
Returns: a free chunk from that block. If a ne w memory block cannot be allocated, returns 0. Amortized O(1).
9.void*ordered_malloc ();
Same as malloc, only mer ges the free lists, to preserv e order . Amortized O(1).
Returns: a free chunk from that block. If a ne w memory block cannot be allocated, returns 0. Amortized O(1).
10.void*ordered_malloc (size_type  n);
Gets address of a chunk n, allocating ne w memory if not already a vailable.
Returns: Address of chunk n if allocated ok.
0 if not enough memory for n chunks.
11.voidfree(void*const chunk);
Same as malloc, only allocates enough contiguous chunks to co ver n * requested_size bytes. Amortized O(n).
Deallocates a chunk of memory . Note that chunk may not be 0. O(1).
Chunk must ha ve been pre viously 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 ne w memory block cannot be allocated, returns 0. Amortized O(1).
12.voidordered_free (void*const chunk);
Same as abo ve, but is order -preserving.
Note that chunk may not be 0. O(N) with respect to the size of the free list. chunk must ha ve been pre viously returned by t.malloc()
or t.ordered_malloc().
13.voidfree(void*const chunks,constsize_type  n);
Assumes that chunk actually refers to a block of chunks.
30Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/chunk must ha ve been pre viously 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.voidordered_free (void*const chunks,constsize_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 ha ve been pre viously
returned by t.malloc() or t.ordered_malloc().
15.boolis_from(void*const chunk)const;
Returns: Returns true if chunk w as allocated from u or may be returned as the result of a future allocation from u. Returns
false if chunk w as allocated from some other pool or may be returned as the result of a future allocation from some
other pool. Otherwise, the return v alue is meaningless. Note that this function may not be used to reliably test random
pointer v alues.
Header < boost/pool/pool_alloc.hpp >
C++ Standard Library compatible pool-based allocators.
This header pro vides tw o template types - pool_allocator and f ast_pool_allocator - that can be used for f ast 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 the y can be
used with either Standard or user -supplied containers.
In addition, the f ast_pool_allocator also pro vides an additional allocation and an additional deallocation function:
Semantic Equi valence Retur n Type Expr ession
PoolAlloc::allocate(1) T * PoolAlloc::allocate()
PoolAlloc::dealloc-
ate(p, 1)void PoolAlloc::dealloc-
ate(p)
The typedef user_allocator publishes the v alue of the UserAllocator template parameter .
Notes
If the allocation functions run out of memory , they will thro w std::bad_alloc .
The underlying Pool type used by the allocators is accessible through the Singleton Pool Interf ace. The identifying tag used for
pool_allocator is pool_allocator_tag, and the tag used for f ast_pool_allocator is f ast_pool_allocator_tag. All template parameters of
the allocators (including implementation-specific ones) determine the type of the underlying Pool, with the e xception 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 dif ferent types of the same size will share
the same underlying pool. The tag class pre vents pools from being shared between pool_allocator and f ast_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
31Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/A number of common STL libraries contain b ugs in their using of allocators. Specifically , they pass null pointers to the deallocate
function, which is e xplicitly forbidden by the Standard [20.1.5 Table 32]. PoolAlloc will w ork around these libraries if it detects
them; currently , workarounds are in place for: Borland C++ (Builder and command-line compiler) with def ault (RogueW ave) library ,
ver. 5 and earlier , STLport (with an y compiler), v er. 4.0 and earlier .
namespace boost{
structpool_allocator_tag ;
template <typename  T,typename  UserAllocator ,typename  Mutex,
unsigned  NextSize ,unsigned  MaxSize >
classpool_allocator ;
template <typename  UserAllocator ,typename  Mutex,unsigned  NextSize ,
unsigned  MaxSize >
classpool_allocator <void,UserAllocator ,Mutex,NextSize ,MaxSize>;
structfast_pool_allocator_tag ;
template <typename  T,typename  UserAllocator ,typename  Mutex,
unsigned  NextSize ,unsigned  MaxSize >
classfast_pool_allocator ;
template <typename  UserAllocator ,typename  Mutex,unsigned  NextSize ,
unsigned  MaxSize >
classfast_pool_allocator <void,UserAllocator ,Mutex,NextSize ,MaxSize>;
}
Struct pool_allocator_ta g
boost::pool_allocator_tag
Synopsis
// In header: < boost/pool/pool_alloc.hpp >
structpool_allocator_tag {
};
Description
Simple tag type used by pool_allocator  as an ar gument to the underlying singleton_pool .
Class template pool_allocator
boost::pool_allocator —A C++ Standard Library conforming allocator , based on an underlying pool.
32Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Synopsis
// In header: < boost/pool/pool_alloc.hpp >
template <typename  T,typename  UserAllocator ,typename  Mutex,
unsigned  NextSize ,unsigned  MaxSize >
classpool_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 constvalue_type * const_pointer ;
typedef value_type & reference ;
typedef constvalue_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>
structrebind{
// types
typedef pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >other;
};
// construct/copy/destruct
pool_allocator ();
template <typename  U>
pool_allocator (constpool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >&);
// public member functions
booloperator ==(constpool_allocator &)const;
booloperator !=(constpool_allocator &)const;
// public static functions
staticpointer address(reference );
staticconst_pointer address(const_reference );
staticsize_type max_size ();
staticvoidconstruct (constpointer,constvalue_type &);
staticvoiddestroy(constpointer);
staticpointer allocate (constsize_type );
staticpointer allocate (constsize_type ,constvoid*);
staticvoiddeallocate (constpointer,constsize_type );
// public data members
staticconstunsigned next_size ;// next_size publishes the values of the template parameter ↵
NextSize. 
};
Description
Template parameters for pool_allocator  are defined as follo ws:
TType of object to allocate/deallocate.
33Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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 v alue 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 ne ver fr eed. This means
that memory allocated by the allocator can be still used after main() has completed, b ut may mean that some memory
checking programs will complain about leaks.
pool_allocator  pub lic construct/cop y/destruct
1.pool_allocator ();
Results in def ault 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 tick et #2359 for a complete e xplanation at http://svn.boost.or g/trac/boost/tick et/2359 ) .
2.template <typename  U>
pool_allocator (constpool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >&);
Results in the def ault 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 tick et #2359 for a complete e xplanation at ht-
tp://svn.boost.or g/trac/boost/tick et/2359  .
pool_allocator  pub lic member functions
1.booloperator ==(constpool_allocator &)const;
2.booloperator !=(constpool_allocator &)const;
pool_allocator  pub lic static functions
1.staticpointer address(reference  r);
2.staticconst_pointer address(const_reference  s);
3.staticsize_type max_size ();
4.staticvoidconstruct (constpointer ptr,constvalue_type & t);
34Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/5.staticvoiddestroy(constpointer ptr);
6.staticpointer allocate (constsize_type  n);
7.staticpointer allocate (constsize_type  n,constvoid* const);
allocate n bytes
Parameters: nbytes to allocate.
8.staticvoiddeallocate (constpointer ptr,constsize_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 allo ws 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>
structrebind{
// types
typedef pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >other;
};
Description
Nested class rebind allo ws for transformation from pool_allocator<T> to pool_allocator<U> via the member typedef other .
Specializations
•Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>
Class template pool_allocator<v oid, UserAllocator , Mute x, NextSiz e, MaxSiz e>
boost::pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize> — Specialization of pool_allocator<v oid>.
35Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Synopsis
// In header: < boost/pool/pool_alloc.hpp >
template <typename  UserAllocator ,typename  Mutex,unsigned  NextSize ,
unsigned  MaxSize >
classpool_allocator <void,UserAllocator ,Mutex,NextSize ,MaxSize>{
public:
// types
typedef void* pointer;
typedef constvoid*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>
structrebind{
// types
typedef pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >other;
};
};
Description
Specialization of pool_allocator  for type v oid: required by the standard to mak e this a conforming allocator type.
Struct template rebind
boost::pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>::rebind — Nested class rebind allo ws 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>
structrebind{
// types
typedef pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >other;
};
Description
Nested class rebind allo ws for transformation from pool_allocator<T> to pool_allocator<U> via the member typedef other .
Struct fast_pool_allocator_ta g
boost::f ast_pool_allocator_tag —Simple tag type used by fast_pool_allocator  as a template parameter to the underlying singleton_pool .
36Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Synopsis
// In header: < boost/pool/pool_alloc.hpp >
structfast_pool_allocator_tag {
};
Class template fast_pool_allocator
boost::f ast_pool_allocator —A C++ Standard Library conforming allocator geared to wards allocating single chunks.
Synopsis
// In header: < boost/pool/pool_alloc.hpp >
template <typename  T,typename  UserAllocator ,typename  Mutex,
unsigned  NextSize ,unsigned  MaxSize >
classfast_pool_allocator {
public:
// types
typedef T value_type ;
typedef UserAllocator user_allocator ;
typedef Mutex mutex;
typedef value_type * pointer;
typedef constvalue_type * const_pointer ;
typedef value_type & reference ;
typedef constvalue_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>
structrebind{
// types
typedef fast_pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >other;
};
// construct/copy/destruct
fast_pool_allocator ();
template <typename  U>
fast_pool_allocator (constfast_pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >&);
// public member functions
voidconstruct (constpointer,constvalue_type &);
voiddestroy(constpointer);
booloperator ==(constfast_pool_allocator &)const;
booloperator !=(constfast_pool_allocator &)const;
// public static functions
staticpointer address(reference );
staticconst_pointer address(const_reference );
staticsize_type max_size ();
staticpointer allocate (constsize_type );
staticpointer allocate (constsize_type ,constvoid*);
staticpointer allocate ();
37Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/staticvoiddeallocate (constpointer,constsize_type );
staticvoiddeallocate (constpointer);
// public data members
staticconstunsigned next_size ;
};
Description
While class template pool_allocator  is a more general-purpose solution geared to wards efficiently servicing requests for an y
number of contiguous chunks, fast_pool_allocator  is also a general-purpose solution, b ut is geared to wards efficiently servicing
requests for one chunk at a time; it will w ork for contiguous chunks, b ut 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 follo ws:
TType 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 v alue 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 ne ver fr eed. This means
that memory allocated by the allocator can be still used after main() has completed, b ut may mean that some memory
checking programs will complain about leaks.
fast_pool_allocator  pub lic construct/cop y/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 tick et #2359 for a complete e xplanation at http://svn.boost.or g/trac/boost/tick et/2359  .
2.template <typename  U>
fast_pool_allocator (constfast_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 tick et #2359 for a complete e xplanation at http://svn.boost.or g/trac/boost/tick et/2359  .
fast_pool_allocator  pub lic member functions
1.voidconstruct (constpointer ptr,constvalue_type & t);
2.voiddestroy(constpointer ptr);
38Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Destro y ptr using destructor .
3.booloperator ==(constfast_pool_allocator &)const;
4.booloperator !=(constfast_pool_allocator &)const;
fast_pool_allocator  pub lic static functions
1.staticpointer address(reference  r);
2.staticconst_pointer address(const_reference  s);
3.staticsize_type max_size ();
4.staticpointer allocate (constsize_type  n);
5.staticpointer allocate (constsize_type  n,constvoid* const);
Allocate memory .
6.staticpointer allocate ();
Allocate memory .
7.staticvoiddeallocate (constpointer ptr,constsize_type  n);
Deallocate memory .
8.staticvoiddeallocate (constpointer ptr);
deallocate/free
Struct template rebind
boost::f ast_pool_allocator::rebind — Nested class rebind allo ws for transformation from f ast_pool_allocator<T> to f ast_pool_alloc-
ator<U>.
39Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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>
structrebind{
// types
typedef fast_pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >other;
};
Description
Nested class rebind allo ws for transformation from f ast_pool_allocator<T> to f ast_pool_allocator<U> via the member typedef other .
Specializations
•Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>
Class template fast_pool_allocator<v oid, UserAllocator , Mute x, NextSiz e,
MaxSiz e>
boost::f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize> — Specialization of f ast_pool_allocator<v oid>.
Synopsis
// In header: < boost/pool/pool_alloc.hpp >
template <typename  UserAllocator ,typename  Mutex,unsigned  NextSize ,
unsigned  MaxSize >
classfast_pool_allocator <void,UserAllocator ,Mutex,NextSize ,MaxSize>{
public:
// types
typedef void* pointer;
typedef constvoid*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>
structrebind{
// types
typedef fast_pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >other;
};
};
Description
Specialization of f ast_pool_allocator<v oid> required to mak e the allocator standard-conforming.
40Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Struct template rebind
boost::f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>::rebind — Nested class rebind allo ws for transformation
from f ast_pool_allocator<T> to f ast_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>
structrebind{
// types
typedef fast_pool_allocator <U,UserAllocator ,Mutex,NextSize ,MaxSize >other;
};
Description
Nested class rebind allo ws for transformation from f ast_pool_allocator<T> to f ast_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_stora ge.hpp >
Simple Se gregated Storage.
A simple se gregated storage implementation: simple se gregated storage is the basic idea behind the Boost Pool library . Simple se-
gregated storage is the simplest, and probably the f astest, memory allocation/deallocation algorithm. It be gins by partitioning a
memory block into fix ed-size chunks. Where the block comes from is not important until implementation time. A Pool is some object
that uses Simple Se gregated Storage in this f ashion.
BOOST_POOL_VALIDATE_INTERNALS
namespace boost{
template <typename  SizeType >classsimple_segregated_storage ;
}
Class template simple_segregated_stora ge
boost::simple_se gregated_storage —Simple Se gregated Storage is the simplest, and probably the f astest, memory allocation/deal-
location algorithm. It is responsible for partitioning a memory block into fix ed-size chunks: where the block comes from is determined
by the client of the class.
41Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Synopsis
// In header: < boost/pool/simple_segregated_storage.hpp >
template <typename  SizeType >
classsimple_segregated_storage {
public:
// types
typedef SizeType size_type ;
// construct/copy/destruct
simple_segregated_storage (constsimple_segregated_storage &);
simple_segregated_storage ();
  simple_segregated_storage& operator =(constsimple_segregated_storage &);
// private static functions
staticvoid*try_malloc_n (void*&,size_type ,size_type );
// protected member functions
void*find_prev (void*);
// protected static functions
staticvoid*&nextof(void*const);
// public member functions
voidadd_block (void*const,constsize_type ,constsize_type );
voidadd_ordered_block (void*const,constsize_type ,constsize_type );
boolempty()const;
void*malloc();
voidfree(void*const);
voidordered_free (void*const);
void*malloc_n (size_type ,size_type );
voidfree_n(void*const,constsize_type ,constsize_type );
voidordered_free_n (void*const,constsize_type ,constsize_type );
// public static functions
staticvoid*segregate (void*,size_type ,size_type ,void*=0);
};
Description
Template class simple_se gregated_storage  controls access to a free list of memory chunks. Please note that this is a v ery simple
class, with preconditions on almost all its functions. It is intended to be the f astest and smallest possible quick memory allocator -
e.g., something to use in embedded systems. This class dele gates man y difficult preconditions to the user (i.e., alignment issues).
An object of type simple_se gregated_storage<SizeT ype> 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 v alues, 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  pub lic construct/cop y/destruct
1.simple_segregated_storage (constsimple_segregated_storage &);
2.simple_segregated_storage ();
Construct empty storage area.
Postconditions: empty()
42Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/3.simple_segregated_storage& operator =(constsimple_segregated_storage &);
simple_segregated_storage  priv ate static functions
1.staticvoid*
try_malloc_n (void*& start,size_type  n,size_type  partition_size );
Requires: (n > 0), (start != 0), (ne xtof(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 kno wn by [start, {retv al}] If it f ails, 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 ne xtof(start) == 0. Otherwise, start points to the last chunk in the contiguous
sequence, and ne xtof(start) points to the first chunk in the ne xt 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 pre vious to where "ptr" w ould go if it w as in the free list. Returns
0 if "ptr" w ould go at the be ginning of the free list (i.e., before "first").
Note
Note that this function finds the location pre vious to where ptr w ould go if it w as 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_pre v(0) will return 0,
not the last entry in the free list.
Returns: location pre vious to where ptr w ould go if it w as in the free list.
simple_segregated_storage  protected static functions
1.staticvoid*&nextof(void*const ptr);
The return v alue is just *ptr cast to the appropriate type. ptr must not be 0. (F or the sak e of code readability :)
As an e xample, let us assume that we w ant to truncate the free list after the first chunk. That is, we w ant to set *first to 0; this
will result in a free list with only one entry . The normal w ay to do this is to first cast first to a pointer to a pointer to v oid, and
then dereference and assign (*static_cast<v oid **>(first) = 0;). This can be done more easily through the use of this con venience
function (ne xtof(first) = 0;).
Returns: dereferenced pointer .
simple_segregated_storage  pub lic member functions
1.voidadd_block (void*const block,constsize_type  nsz,
constsize_type  npartition_sz );
Add block Se gregate this block and mer ge its free list into the free list referred to by "first".
Requires: Same as se gregate.
Postconditions: !empty()
43Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/2.voidadd_ordered_block (void*const block,constsize_type  nsz,
constsize_type  npartition_sz );
add block (ordered into list) This (slo wer) v ersion of add_block se gregates the block and mer ges its free list into our free list in
the proper order .
3.boolempty()const;
Returns: true only if simple_se gregated_storage  is empty .
4.void*malloc();
Create a chunk.
Requires: !empty() Increment the "first" pointer to point to the ne xt chunk.
5.voidfree(void*const chunk);
Free a chunk.
Requires: chunk w as pre viously returned from a malloc() referring to the same free list.
Postconditions: !empty()
6.voidordered_free (void*const chunk);
This (slo wer) implementation of 'free' places the memory back in the list in its proper order .
Requires: chunk w as pre viously 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, remo ves them all from the free list and returns
a pointer to the first. If not found, returns 0. It is strongly recommended (b ut not required) that the free list be ordered, as this al-
gorithm will f ail 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.voidfree_n(void*const chunks,constsize_type  n,
constsize_type  partition_size );
Note
If you're allocating/deallocating n a lot, you should be using an ordered pool.
Requires: chunks w as pre viously allocated from *this with the same v alues for n and partition_size.
Postconditions: !empty()
9.voidordered_free_n (void*const chunks,constsize_type  n,
constsize_type  partition_size );
Free n chunks from order list.
Requires: chunks w as pre viously allocated from *this with the same v alues for n and partition_size.
n should not be zero (n == 0 has no ef fect).
44Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/simple_segregated_storage  pub lic static functions
1.staticvoid*
segregate (void* block,size_type  nsz,size_type  npartition_sz ,
void* end =0);
Segregate block into chunks.
Requires: npartition_sz >= sizeof(v oid *)
npartition_sz = sizeof(v oid *) * i, for some inte ger i
nsz >= npartition_sz
Block is properly aligned for an array of object of size npartition_sz and array of v oid *. The requirements abo ve
guarantee that an y pointer to a chunk (which is a pointer to an element in an array of npartition_sz) may be cast
to void **.
Macr o BOOST_POOL_V ALID ATE_INTERNALS
BOOST_POOL_V ALID ATE_INTERN ALS
Synopsis
// In header: < boost/pool/simple_segregated_storage.hpp >
BOOST_POOL_VALIDATE_INTERNALS
Header < boost/pool/singleton_pool.hpp >
The singleton_pool  class allo ws other pool interf aces for types of the same size to share the same underlying pool.
Header singleton_pool.hpp pro vides a template class singleton_pool , which pro vides access to a pool as a singleton object.
namespace boost{
template <typename  Tag,unsigned  RequestedSize ,typename  UserAllocator ,
typename  Mutex,unsigned  NextSize ,unsigned  MaxSize >
classsingleton_pool ;
}
Class template singleton_pool
boost::singleton_pool
45Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Synopsis
// In header: < boost/pool/singleton_pool.hpp >
template <typename  Tag,unsigned  RequestedSize ,typename  UserAllocator ,
typename  Mutex,unsigned  NextSize ,unsigned  MaxSize >
classsingleton_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
structobject_creator {
// construct/copy/destruct
object_creator ();
// public member functions
voiddo_nothing ()const;
};
// construct/copy/destruct
singleton_pool ();
// public static functions
staticvoid*malloc();
staticvoid*ordered_malloc ();
staticvoid*ordered_malloc (constsize_type );
staticboolis_from(void*const);
staticvoidfree(void*const);
staticvoidordered_free (void*const);
staticvoidfree(void*const,constsize_type );
staticvoidordered_free (void*const,constsize_type );
staticboolrelease_memory ();
staticboolpurge_memory ();
// private static functions
staticpool_type &get_pool ();
// public data members
staticconstunsigned requested_size ;// The size of each chunk allocated by this pool. 
staticconstunsigned next_size ;// The number of chunks to allocate on the first allocation. 
staticpool<UserAllocator >p;// For exposition only! 
};
Description
The singleton_pool  class allo ws other pool interf aces 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: allo ws dif ferent unbounded sets of singleton pools to e xist.
RequestedSize The size of each chunk returned by member function malloc() .
UserAllocator  User allocator , default = default_user_allocator_ne w_delete .
46Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Mutex This class is the type of mute x to use to protect simultaneous access to the underlying Pool. Can be an y Boost.Thread Mute x
type or boost::details::pool::null_mutex . It is e xposed so that users may declare some singleton pools normally (i.e., with
synchronization), b ut some singleton pools without synchronization (by specifying boost::details::pool::null_mutex ) for
efficienc y reasons. The member typedef mutex  exposes the v alue of this template parameter . The def ault for this parameter is
boost::details::pool::def ault_mute x which is a synon ym for either boost::details::pool::null_mutex  (when threading support
is turned of f in the compiler (so BOOST_HAS_THREADS is not set), or threading support has ben e xplicitly 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 v alue 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 (def aults to 32). The member typedef static const value next_size  exposes the v alue of this
template parameter .
MaxSize The v alue of this parameter is passed to the underlying Pool when it is created and specifies the maximum number of chunks
to allocate in an y single allocation request (def aults to 0).
Notes:
The underlying pool p referenced by the static functions in singleton_pool  is actually declared in a w ay that is:
1 Thread-safe if there is only one thread running before main() be gins 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 abo ve would actually be an incorrect
implementation. The actual implementation to guarantee this is considerably more complicated.
3 Note too that a dif ferent underlying pool p e xists for each dif ferent set of template parameters, including implementation-specific
ones.
4 The underlying pool is constructed "as if" by:
pool<UserAllocator> p(RequestedSize, Ne xtSize, MaxSize);
Note
The underlying pool constructed by the singleton is ne ver fr eed. This means that memory allocated by a
singleton_pool  can be still used after main() has completed, b ut may mean that some memory checking programs
will complain about leaks from singleton_pool .
singleton_pool  pub lic types
1.typedef Tagtag;
The Tag template parameter uniquely identifies this pool and allo ws dif ferent unbounded sets of singleton pools to e xist. F or ex-
ample, the pool allocators use tw o tag classes to ensure that the tw o dif ferent allocator types ne ver share the same underlying
singleton pool. Tag is ne ver actually used by singleton_pool .
singleton_pool  pub lic construct/cop y/destruct
1.singleton_pool ();
singleton_pool  pub lic static functions
1.staticvoid*malloc();
Equivalent to SingletonPool::p.malloc(); synchronized.
47Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/2.staticvoid*ordered_malloc ();
Equivalent to SingletonPool::p.ordered_malloc(); synchronized.
3.staticvoid*ordered_malloc (constsize_type  n);
Equivalent to SingletonPool::p.ordered_malloc(n); synchronized.
4.staticboolis_from(void*const ptr);
Equivalent to SingletonPool::p.is_from(chunk); synchronized.
Returns: true if chunk is from SingletonPool::is_from(chunk)
5.staticvoidfree(void*const ptr);
Equivalent to SingletonPool::p.free(chunk); synchronized.
6.staticvoidordered_free (void*const ptr);
Equivalent to SingletonPool::p.ordered_free(chunk); synchronized.
7.staticvoidfree(void*const ptr,constsize_type  n);
Equivalent to SingletonPool::p.free(chunk, n); synchronized.
8.staticvoidordered_free (void*const ptr,constsize_type  n);
Equivalent to SingletonPool::p.ordered_free(chunk, n); synchronized.
9.staticboolrelease_memory ();
Equivalent to SingletonPool::p.release_memory(); synchronized.
10.staticboolpurge_memory ();
Equivalent to SingletonPool::p.pur ge_memory(); synchronized.
singleton_pool  priv ate static functions
1.staticpool_type &get_pool ();
Struct object_creator
boost::singleton_pool::object_creator
48Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Synopsis
// In header: < boost/pool/singleton_pool.hpp >
structobject_creator {
// construct/copy/destruct
object_creator ();
// public member functions
voiddo_nothing ()const;
};
Description
object_creator  pub lic construct/cop y/destruct
1.object_creator ();
object_creator  pub lic member functions
1.voiddo_nothing ()const;
49Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Appendices
Appendix A:  Histor y
Version 2.0.0,  January 11,  2011
Documentation and testing r evision
Featur es:
•Fix issues 1252 , 4960 , 5526 , 5700 , 2696 .
•Documentation con verted and re written and re vised by P aul A. Bristo w using Quickbook, Doxygen, for html and pdf, based on
Stephen Cleary's html v ersion, Re vised 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 no w displayed as Quickbook and can be copied and pasted into quickbook files using your f avored te xt editor
for Quickbook.
Version 1.0.0,  January 1, 2000
First release
Appendix B:  FAQ
Why should I use P ool?
Using Pools gi ves you more control o ver ho w memory is used in your program. F or example, you could ha ve a situation where you
want to allocate a b unch of small objects at one point, and then reach a point in your program where none of them are needed an y
more. Using pool interf aces, you can choose to run their destructors or just drop them of f into obli vion; the pool interf ace will
guarantee that there are no system memory leaks.
When should I use P ool?
Pools are generally used when there is a lot of allocation and deallocation of small objects. Another common usage is the situation
above, where man y objects may be dropped out of memory .
In general, use Pools when you need a more efficient w ay to do unusual memory control.
Appendix C:  Acknowledg ements
Many, man y thanks to the Boost peers, notably Jef f Garland, Beman Da wes, Ed Bre y, Gary Po well, Peter Dimo v, and Jens Maurer
for pro viding helpful suggestions!
Appendix D: Tests
See folder boost/libs/pool/test/.
Appendix E: Tickets
Report and vie w bugs and features by adding a tick et at Boost.T rac.
50Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Existing open tick ets for this library alone can be vie wed here. Existing tick ets for this library - including closed ones - can be vie wed
here.
Appendix F:  Other Implementations
Pool allocators are found in man y programming languages, and in man y variations. The be ginnings of man y implementations may
be found in common programming literature; some of these are gi ven belo w. Note that none of these are complete implementations
of a Pool; most of these lea ve some aspects of a Pool as a user e xercise. Ho wever, in each case, e ven though some aspects are
missing, these e xamples use the same underlying concept of a Simple Se gregated Storage described in this document.
1.The C++ Pr ogramming Langua ge, 3rd ed., by Bjarne Stroustrup, Section 19.4.2. Missing aspects:
•Not portable.
•Cannot handle allocations of arbitrary numbers of objects (this w as left as an e xercise).
•Not thread-safe.
•Suffers from the static initialization problem.
2.Micr oC/OS-II: The Real-T ime K ernel , by Jean J. Labrosse, Chapter 7 and Appendix B.04.
•An e xample of the Simple Se gregated Storage scheme at w ork in the internals of an actual OS.
•Missing aspects:
•Not portable (though this is OK, since it's part of its o wn OS).
•Cannot handle allocations of arbitrary numbers of blocks (which is also OK, since this feature is not needed).
•Requires non-intuiti ve user code to create and destro y the Pool.
3.Efficient C++: P erformance Pr ogramming Techniques , by Do v Bulka and Da vid Mayhe w, Chapters 6 and 7.
•This is a good e xample of iterati vely de veloping a Pool solutio.
•however, their premise (that the system-supplied allocation mechanism is hopelessly inefficient) is fla wed on e very system
I've tested on.
•Run their timings on your system before you accept their conclusions.
•Missing aspect: Requires non-intuiti ve user code to create and destro y the Pool.
4.Advanced C++: Pr ogramming Styles and Idioms , by James O. Coplien, Section 3.6.
•Has e xamples of both static and dynamic pooling, b ut missing aspects:
•Not thread-safe.
•The static pooling e xample is not portable.
Appendix G:  References
1.Doug Lea, A Memory Allocator . See http://gee.cs.oswe go.edu/dl/html/malloc.html
2.Paul R. Wilson, Mark S. Johnstone, Michael Neely , and Da vid Boles, Dynamic Stor age Allocation: A Surve y and Critical Re view
in International Workshop on Memory Management, September 1995, pg. 28, 36. See ftp://ftp.cs.ute xas.edu/pub/g arbage/allocsrv .ps
51Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Appendix H:  Future plans
Another pool interf ace will be written: a base class for per -class pool allocation.
This "pool_base" interf ace will be Singleton Usage with Exceptions, and b uilt on the singleton_pool interf ace.
52Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Indexes
Function Inde x
A
address
Class template f ast_pool_allocator , 37, 39
Class template pool_allocator , 33, 34
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
pool_allocator , 8
add_block
Class template simple_se gregated_storage, 42, 43
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
add_ordered_block
Class template simple_se gregated_storage, 42, 44
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
allocate
Class template f ast_pool_allocator , 37, 39
Class template pool_allocator , 33, 35
pool_allocator , 8
C
construct
Class template f ast_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 f ast_pool_allocator , 37, 39
Class template pool_allocator , 33, 35
pool_allocator , 8
destro y
Class template f ast_pool_allocator , 37, 38
Class template object_pool, 22, 24
Class template pool_allocator , 33, 35
Object_pool, 6
pool_allocator , 8
F
find_pre v
Class template simple_se gregated_storage, 42, 43
free
Class template object_pool, 22, 23
Class template pool, 27, 30
Class template simple_se gregated_storage, 42, 44
Class template singleton_pool, 46, 48
Object_pool, 6
pool, 4
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25, 26
53Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/free_n
Class template simple_se gregated_storage, 42, 44
Simple Se gregated Storage (Not for the f aint 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 f ast_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_se gregated_storage, 42, 44
Class template singleton_pool, 46, 47
Object_pool, 6
pool, 4
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25, 26
malloc_n
Class template simple_se gregated_storage, 42, 44
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
malloc_need_resize
Class template pool, 27, 28
max_size
Class template f ast_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_se gregated_storage, 42, 43
O
ordered_free
Class template pool, 27, 30, 31
Class template simple_se gregated_storage, 42, 44
Class template singleton_pool, 46, 48
54Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/pool, 4
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
ordered_free_n
Class template simple_se gregated_storage, 42, 44
Simple Se gregated Storage (Not for the f aint 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_se gregated_storage, 42, 45
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
set_max_size
Class template pool, 27, 30
set_ne xt_size
Class template object_pool, 22, 25
Class template pool, 27, 29
sizeof
Guaranteeing Alignment - Ho w 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_se gregated_storage, 42, 43
Class Inde x
D
default_user_allocator_malloc_free
pool, 4
Struct def ault_user_allocator_malloc_free, 26
default_user_allocator_ne w_delete
pool, 4
Struct def ault_user_allocator_ne w_delete, 25
55Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/F
fast_pool_allocator
Class template f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
pool_allocator , 8
Struct template rebind, 40, 41
fast_pool_allocator_tag
pool_allocator , 8
Struct f ast_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<v oid, UserAllocator , Mute x, Ne xtSize, 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 f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
Struct template rebind, 35, 36, 40, 41
S
simple_se gregated_storage
Class template pool, 27
Class template simple_se gregated_storage, 42
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
singleton_pool
Class template singleton_pool, 45, 46, 47, 48
Singleton_pool, 7
Typedef Inde x
C
const_pointer
Class template f ast_pool_allocator , 37
56Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
const_reference
Class template f ast_pool_allocator , 37
Class template pool_allocator , 33
pool_allocator , 8
D
difference_type
Class template f ast_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 def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25
E
element_type
Class template object_pool, 22
Object_pool, 6
M
mute x
Class template f ast_pool_allocator , 37
Class template pool_allocator , 33
Class template singleton_pool, 46
O
other
Class template f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
Struct template rebind, 35, 36, 40, 41
P
pointer
Class template f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
R
reference
Class template f ast_pool_allocator , 37
Class template pool_allocator , 33
pool_allocator , 8
57Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/S
size_type
Class template f ast_pool_allocator , 37
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator , 33
Class template simple_se gregated_storage, 42
Class template singleton_pool, 46
Object_pool, 6
pool, 4
pool_allocator , 8
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25
T
tag
Class template singleton_pool, 46, 47
Singleton_pool, 7
U
user_allocator
Class template f ast_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 f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
Index
A
address
Class template f ast_pool_allocator , 37, 39
Class template pool_allocator , 33, 34
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
pool_allocator , 8
add_block
Class template simple_se gregated_storage, 42, 43
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
add_ordered_block
Class template simple_se gregated_storage, 42, 44
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
alignment
58Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Class template pool, 26
Class template simple_se gregated_storage, 42
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
Header < boost/pool/pool.hpp >, 25
How Contiguous Chunks are Handled, 15
pool, 4
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
allocate
Class template f ast_pool_allocator , 37, 39
Class template pool_allocator , 33, 35
pool_allocator , 8
allocation
Allocation and Deallocation, 16
Appendix B: F AQ, 50
Appendix F: Other Implementations, 51
Appendix G: References, 51
Appendix H: Future plans, 52
Basic ideas behind pooling, 10
Boost Pool Interf aces - What interf aces are pro vided and when to use each one., 3
Class template object_pool, 22, 24
Class template pool, 27, 29, 31
Class template simple_se gregated_storage, 41
Class template singleton_pool, 46
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
Header < boost/pool/object_pool.hpp >, 22
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/simple_se gregated_storage.hpp >, 41
How Contiguous Chunks are Handled, 15
Introduction, 2
Object_pool, 6
pool_allocator , 8
Simple Se gregated Storage, 12
Allocation and Deallocation
allocation, 16
block, 16
chunk, 16
deallocation, 16
malloc, 16
ordered, 16
size, 16
Appendix B: F AQ
allocation, 50
deallocation, 50
interf ace, 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
59Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Appendix H: Future plans
allocation, 52
interf ace, 52
singleton, 52
singleton_pool, 52
automatic
Class template object_pool, 22
Guaranteeing Alignment - Ho w 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 Interf aces - What interf aces are pro vided and when to use each one., 3
Class template object_pool, 23
Class template pool, 28, 29, 30, 31
Class template simple_se gregated_storage, 41, 43, 44, 45
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13, 14
Header < boost/pool/simple_se gregated_storage.hpp >, 41
How Contiguous Chunks are Handled, 15
pool, 4
Segregation, 16
Simple Se gregated Storage, 12
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 26
Symbol Table, 16
The UserAllocator Concept, 21
UserAllocator Requirements, 21
Boost Pool Interf aces - What interf aces are pro vided and when to use each one.
allocation, 3
block, 3
chunk, 3
concepts, 3
interf ace, 3
memory , 3
objects, 3
ordered, 3
singleton, 3
BOOST_POOL_V ALID ATE_INTERN ALS
Header < boost/pool/simple_se gregated_storage.hpp >, 41
Macro BOOST_POOL_V ALID ATE_INTERN ALS, 45
60Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/build
Installation, 3
Building the Test Programs
jamfile, 3
C
chunk
Allocation and Deallocation, 16
Basic ideas behind pooling, 10
Boost Pool Interf aces - What interf aces are pro vided and when to use each one., 3
Class template f ast_pool_allocator , 37, 38
Class template object_pool, 23, 24, 25
Class template pool, 26, 27, 28, 29, 30, 31
Class template simple_se gregated_storage, 41, 42, 43, 44, 45
Class template singleton_pool, 46, 48
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13, 14
Header < boost/pool/pool.hpp >, 25
Header < boost/pool/simple_se gregated_storage.hpp >, 41
How Contiguous Chunks are Handled, 15
Introduction, 2
Object_pool, 6
pool, 4
Segregation, 16
Simple Se gregated Storage, 12
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Symbol Table, 16
The UserAllocator Concept, 21
Class template f ast_pool_allocator
address, 37, 39
allocate, 37, 39
chunk, 37, 38
construct, 37, 38
const_pointer , 37
const_reference, 37
deallocate, 37, 39
destro y, 37, 38
difference_type, 37
fast_pool_allocator , 37
headers, 37
main, 38
max_size, 37, 39
memory , 38, 39
mute x, 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 f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>
61Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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
destro y, 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_ne xt_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
62Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/set_ne xt_size, 27, 29
simple_se gregated_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
destro y, 33, 35
difference_type, 33
headers, 33
main, 33
max_size, 33, 34
memory , 33
mute x, 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<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>
const_pointer , 36
headers, 36
other , 36
pointer , 36
pool_allocator , 36
rebind, 36
template, 35, 36
value_type, 36
Class template simple_se gregated_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_pre v, 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
63Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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_se gregated_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
interf ace, 46
is_from, 46, 48
main, 46
malloc, 46, 47
memory , 46
mute x, 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 Interf aces - What interf aces are pro vided and when to use each one., 3
Documentation Naming and F ormatting Con ventions, 2
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
Introduction, 2
The UserAllocator Concept, 21
construct
Class template f ast_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 f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
64Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
const_reference
Class template f ast_pool_allocator , 37
Class template pool_allocator , 33
pool_allocator , 8
conventions
Documentation Naming and F ormatting Con ventions, 2
D
deallocate
Class template f ast_pool_allocator , 37, 39
Class template pool_allocator , 33, 35
pool_allocator , 8
deallocation
Allocation and Deallocation, 16
Appendix B: F AQ, 50
Class template simple_se gregated_storage, 41
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/simple_se gregated_storage.hpp >, 41
Introduction, 2
Simple Se gregated Storage, 12
default_user_allocator_malloc_free
pool, 4
Struct def ault_user_allocator_malloc_free, 26
default_user_allocator_ne w_delete
pool, 4
Struct def ault_user_allocator_ne w_delete, 25
destro y
Class template f ast_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 f ast_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 def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25
Documentation Naming and F ormatting Con ventions
concepts, 2
conventions, 2
include, 2
naming, 2
objects, 2
template, 2
E
elements
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
65Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/element_type
Class template object_pool, 22
Object_pool, 6
F
fast_pool_allocator
Class template f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
pool_allocator , 8
Struct template rebind, 40, 41
fast_pool_allocator_tag
pool_allocator , 8
Struct f ast_pool_allocator_tag, 37
find_pre v
Class template simple_se gregated_storage, 42, 43
free
Class template object_pool, 22, 23
Class template pool, 27, 30
Class template simple_se gregated_storage, 42, 44
Class template singleton_pool, 46, 48
Object_pool, 6
pool, 4
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25, 26
free_n
Class template simple_se gregated_storage, 42, 44
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
G
get_pool
Class template singleton_pool, 46, 48
Guaranteeing Alignment - Ho w 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
overvie w, 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
66Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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
interf ace, 31
main, 31
memory , 31
singleton, 31
size, 31
sizeof, 31
template, 31
Header < boost/pool/simple_se gregated_storage.hpp >
allocation, 41
block, 41
BOOST_POOL_V ALID ATE_INTERN ALS, 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
interf ace, 45
objects, 45
singleton, 45
singleton_pool, 45
size, 45
template, 45
headers
Basic ideas behind pooling, 10
Class template f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
Class template simple_se gregated_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
67Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Header < boost/pool/simple_se gregated_storage.hpp >, 41
Header < boost/pool/singleton_pool.hpp >, 45
How do I use Pool?, 3
Installation, 3
Macro BOOST_POOL_V ALID ATE_INTERN ALS, 45
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25
Struct f ast_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
interf ace, 3
I
include
Class template object_pool, 24
Documentation Naming and F ormatting Con ventions, 2
How do I use Pool?, 3
Installation, 3
Installation
build, 3
headers, 3
include, 3
installation, 3
installation
Installation, 3
interf ace
Appendix B: F AQ, 50
Appendix H: Future plans, 52
Boost Pool Interf aces - What interf aces are pro vided 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 Interf aces, 4
pool_allocator , 8
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
The UserAllocator Concept, 21
Introduction
68Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/allocation, 2
chunk, 2
concepts, 2
deallocation, 2
interf ace, 2
memory , 2
objects, 2
segregated, 2
Introduction and Ov ervie w
overvie w, 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_V ALID ATE_INTERN ALS
BOOST_POOL_V ALID ATE_INTERN ALS, 45
headers, 45
segregated, 45
main
Class template f ast_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_se gregated_storage, 42, 44
Class template singleton_pool, 46, 47
Object_pool, 6
pool, 4
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25, 26
UserAllocator Requirements, 21
malloc_n
Class template simple_se gregated_storage, 42, 44
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
malloc_need_resize
Class template pool, 27, 28
max_size
Class template f ast_pool_allocator , 37, 39
Class template pool_allocator , 33, 34
pool_allocator , 8
69Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/memory
Appendix B: F AQ, 50
Appendix G: References, 51
Basic ideas behind pooling, 10
Boost Pool Interf aces - What interf aces are pro vided and when to use each one., 3
Class template f ast_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_se gregated_storage, 41, 42, 44
Class template singleton_pool, 46
Guaranteeing Alignment - Ho w 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_se gregated_storage.hpp >, 41
How Contiguous Chunks are Handled, 15
Introduction, 2
Object_pool, 6
pool, 4
pool_allocator , 8
Segregation, 16
Simple Se gregated Storage, 12
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_ne w_delete, 25
The UserAllocator Concept, 21
UserAllocator Requirements, 21
mute x
Class template f ast_pool_allocator , 37
Class template pool_allocator , 33
Class template singleton_pool, 46
N
naming
Documentation Naming and F ormatting Con ventions, 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 - Ho w we guarantee alignment portably ., 13
pool, 4
Struct def ault_user_allocator_ne w_delete, 25
nextof
Class template object_pool, 22, 23
Class template pool, 27, 29
Class template simple_se gregated_storage, 42, 43
O
objects
Appendix B: F AQ, 50
Appendix F: Other Implementations, 51
Basic ideas behind pooling, 10
Boost Pool Interf aces - What interf aces are pro vided and when to use each one., 3
Class template f ast_pool_allocator , 38
Class template object_pool, 22, 23, 24
70Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Class template pool, 27, 28, 29, 30
Class template pool_allocator , 33
Class template simple_se gregated_storage, 42, 45
Class template singleton_pool, 46
Documentation Naming and F ormatting Con ventions, 2
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13, 14
Header < boost/pool/object_pool.hpp >, 22
Header < boost/pool/simple_se gregated_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 Se gregated Storage, 12
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_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
destro y, 6
difference_type, 6
element_type, 6
free, 6
interf ace, 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 def ault_user_allocator_malloc_free, 26
ordered
Allocation and Deallocation, 16
Basic ideas behind pooling, 10
Boost Pool Interf aces - What interf aces are pro vided and when to use each one., 3
Class template pool, 27, 28, 29, 30, 31
Class template simple_se gregated_storage, 42, 43, 44
Class template singleton_pool, 46, 48
Constructors, Destructors, and State, 16
71Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/How Contiguous Chunks are Handled, 15
pool, 4
pool_allocator , 8
Segregation, 16
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
ordered_free
Class template pool, 27, 30, 31
Class template simple_se gregated_storage, 42, 44
Class template singleton_pool, 46, 48
pool, 4
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
ordered_free_n
Class template simple_se gregated_storage, 42, 44
Simple Se gregated Storage (Not for the f aint 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 f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
Struct template rebind, 35, 36, 40, 41
overvie w
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
Introduction and Ov ervie w, 2
P
padding
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
How Contiguous Chunks are Handled, 15
pointer
Class template f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, 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_ne w_delete, 4
difference_type, 4
free, 4
interf ace, 4
is_from, 4
malloc, 4
72Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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 Interf aces
interf ace, 4
pool_allocator
address, 8
allocate, 8
allocation, 8
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
construct, 8
const_pointer , 8
const_reference, 8
deallocate, 8
destro y, 8
difference_type, 8
fast_pool_allocator , 8
fast_pool_allocator_tag, 8
interf ace, 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 - Ho w we guarantee alignment portably ., 13
purge_memory
Class template pool, 27, 29
Class template singleton_pool, 46, 48
73Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/pool, 4
Singleton_pool, 7
R
rebind
Class template f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
Struct template rebind, 35, 36, 40, 41
reference
Class template f ast_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_se gregated_storage, 42, 45
Simple Se gregated Storage (Not for the f aint 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_se gregated_storage, 41, 42, 43, 44, 45
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
Header < boost/pool/pool.hpp >, 25
Header < boost/pool/simple_se gregated_storage.hpp >, 41
Introduction, 2
Macro BOOST_POOL_V ALID ATE_INTERN ALS, 45
pool, 4
Simple Se gregated Storage, 12
Simple Se gregated Storage (Not for the f aint 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_ne xt_size
Class template object_pool, 22, 25
Class template pool, 27, 29
Simple Se gregated Storage
allocation, 12
block, 12
chunk, 12
74Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/deallocation, 12
memory , 12
objects, 12
segregated, 12
size, 12
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!)
add_block, 16
add_ordered_block, 16
alignment, 16
block, 16
chunk, 16
free, 16
free_n, 16
interf ace, 16
malloc, 16
malloc_n, 16
memory , 16
objects, 16
ordered, 16
ordered_free, 16
ordered_free_n, 16
segregate, 16
segregated, 16
simple_se gregated_storage, 16
size, 16
size_type, 16
template, 16
simple_se gregated_storage
Class template pool, 27
Class template simple_se gregated_storage, 42
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
singleton
Appendix H: Future plans, 52
Boost Pool Interf aces - What interf aces are pro vided and when to use each one., 3
Class template f ast_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 f ast_pool_allocator_tag, 36
Struct object_creator , 48, 49
Struct pool_allocator_tag, 32
Singleton_pool
chunk, 7
difference_type, 7
free, 7
interf ace, 7
is_from, 7
main, 7
malloc, 7
memory , 7
objects, 7
ordered, 7
ordered_free, 7
ordered_malloc, 7
purge_memory , 7
75Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/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 f ast_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 f ast_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 f ast_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_se gregated_storage, 41, 42, 43, 44, 45
Class template singleton_pool, 46, 48
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13, 14
Header < boost/pool/pool_alloc.hpp >, 31
Header < boost/pool/simple_se gregated_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 Se gregated Storage, 12
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25
Symbol Table, 16
Template P arameters, 16
The UserAllocator Concept, 21
Typedefs, 16
UserAllocator Requirements, 21
sizeof
Guaranteeing Alignment - Ho w we guarantee alignment portably ., 13
Header < boost/pool/pool_alloc.hpp >, 31
How Contiguous Chunks are Handled, 15
size_type
Class template f ast_pool_allocator , 37
Class template object_pool, 22
Class template pool, 27
Class template pool_allocator , 33
Class template simple_se gregated_storage, 42
Class template singleton_pool, 46
76Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/Object_pool, 6
pool, 4
pool_allocator , 8
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25
Struct def ault_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 def ault_user_allocator_ne w_delete
block, 26
default_user_allocator_ne w_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 f ast_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
77Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/chunk, 16
segregated, 16
size, 16
T
tag
Class template singleton_pool, 46, 47
Singleton_pool, 7
template
Class template f ast_pool_allocator , 37, 38, 40
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, 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<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 35, 36
Class template simple_se gregated_storage, 41, 42
Class template singleton_pool, 45, 46, 47
Documentation Naming and F ormatting Con ventions, 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_se gregated_storage.hpp >, 41
Header < boost/pool/singleton_pool.hpp >, 45
Object_pool, 6
pool, 4
pool_allocator , 8
Simple Se gregated Storage (Not for the f aint of heart - Embedded programmers only!), 16
Singleton_pool, 7
Struct def ault_user_allocator_malloc_free, 26
Struct def ault_user_allocator_ne w_delete, 25
Struct f ast_pool_allocator_tag, 36
Struct template rebind, 35, 36, 39, 40, 41
Template P arameters, 16
The UserAllocator Concept, 21
Template P arameters
size, 16
template, 16
try_malloc_n
Class template simple_se gregated_storage, 42, 43
Typedefs
size, 16
U
UserAllocator Concept
block, 21
chunk, 21
concepts, 21
interf ace, 21
memory , 21
objects, 21
size, 21
template, 21
UserAllocator Requirements
block, 21
malloc, 21
memory , 21
objects, 21
78Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/size, 21
user_allocator
Class template f ast_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 f ast_pool_allocator , 37
Class template f ast_pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 40
Class template pool_allocator , 33
Class template pool_allocator<v oid, UserAllocator , Mute x, Ne xtSize, MaxSize>, 36
pool_allocator , 8
79Boost.Pool
XML to PDF by RenderX XEP XSL-FO F ormatter , visit us at http://www .renderx.com/