1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Boost Pool Interfaces - What interfaces are provided and when to use each one.</title> 5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Boost.Pool"> 8<link rel="up" href="../pool.html" title="Introduction and Overview"> 9<link rel="prev" href="testing.html" title="Building the Test Programs"> 10<link rel="next" href="pooling.html" title="Pool in More Depth"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="testing.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pool.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="pooling.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_pool.pool.interfaces"></a><a class="link" href="interfaces.html" title="Boost Pool Interfaces - What interfaces are provided and when to use each one.">Boost Pool Interfaces - What 28 interfaces are provided and when to use each one.</a> 29</h3></div></div></div> 30<div class="toc"><dl class="toc"> 31<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces">Pool Interfaces</a></span></dt> 32<dd><dl> 33<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces.pool">pool</a></span></dt> 34<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces.object_pool">Object_pool</a></span></dt> 35<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces.singleton_pool">Singleton_pool</a></span></dt> 36<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces.pool_allocator">pool_allocator</a></span></dt> 37</dl></dd> 38</dl></div> 39<h5> 40<a name="boost_pool.pool.interfaces.h0"></a> 41 <span class="phrase"><a name="boost_pool.pool.interfaces.introduction"></a></span><a class="link" href="interfaces.html#boost_pool.pool.interfaces.introduction">Introduction</a> 42 </h5> 43<p> 44 There are several interfaces provided which allow users great flexibility 45 in how they want to use Pools. Review the <a class="link" href="pooling.html#boost_pool.pool.pooling.concepts" title="Basic ideas behind pooling">concepts</a> 46 document to get the basic understanding of how the various pools work. 47 </p> 48<h4> 49<a name="boost_pool.pool.interfaces.h1"></a> 50 <span class="phrase"><a name="boost_pool.pool.interfaces.terminology_and_tradeoffs"></a></span><a class="link" href="interfaces.html#boost_pool.pool.interfaces.terminology_and_tradeoffs">Terminology 51 and Tradeoffs</a> 52 </h4> 53<h6> 54<a name="boost_pool.pool.interfaces.h2"></a> 55 <span class="phrase"><a name="boost_pool.pool.interfaces.object_usage_vs__singleton_usage"></a></span><a class="link" href="interfaces.html#boost_pool.pool.interfaces.object_usage_vs__singleton_usage">Object 56 Usage vs. Singleton Usage</a> 57 </h6> 58<p> 59 Object Usage is the method where each Pool is an object that may be created 60 and destroyed. Destroying a Pool implicitly frees all chunks that have been 61 allocated from it. 62 </p> 63<p> 64 Singleton Usage is the method where each Pool is an object with static duration; 65 that is, it will not be destroyed until program exit. Pool objects with Singleton 66 Usage may be shared; thus, Singleton Usage implies thread-safety as well. 67 System memory allocated by Pool objects with Singleton Usage may be freed 68 through release_memory or purge_memory. 69 </p> 70<h6> 71<a name="boost_pool.pool.interfaces.h3"></a> 72 <span class="phrase"><a name="boost_pool.pool.interfaces.out_of_memory_conditions__exceptions_vs__null_return"></a></span><a class="link" href="interfaces.html#boost_pool.pool.interfaces.out_of_memory_conditions__exceptions_vs__null_return">Out-of-Memory 73 Conditions: Exceptions vs. Null Return</a> 74 </h6> 75<p> 76 Some Pool interfaces throw exceptions when out-of-memory; others will <code class="computeroutput"><span class="keyword">return</span> <span class="number">0</span></code>. In 77 general, unless mandated by the Standard, Pool interfaces will always prefer 78 to <code class="computeroutput"><span class="keyword">return</span> <span class="number">0</span></code> 79 instead of throwing an exception. 80 </p> 81<h6> 82<a name="boost_pool.pool.interfaces.h4"></a> 83 <span class="phrase"><a name="boost_pool.pool.interfaces.ordered_versus_unordered"></a></span><a class="link" href="interfaces.html#boost_pool.pool.interfaces.ordered_versus_unordered">Ordered 84 versus unordered</a> 85 </h6> 86<p> 87 An ordered pool maintains it's free list in order of the address of each 88 free block - this is the most efficient way if you're likely to allocate 89 arrays of objects. However, freeing an object can be O(N) in the number of 90 currently free blocks which can be prohibitively expensive in some situations. 91 </p> 92<p> 93 An unordered pool does not maintain it's free list in any particular order, 94 as a result allocation and freeing single objects is very fast, but allocating 95 arrays may be slow (and in particular the pool may not be aware that it contains 96 enough free memory for the allocation request, and unnecessarily allocate 97 more memory). 98 </p> 99<div class="section"> 100<div class="titlepage"><div><div><h4 class="title"> 101<a name="boost_pool.pool.interfaces.interfaces"></a><a class="link" href="interfaces.html#boost_pool.pool.interfaces.interfaces" title="Pool Interfaces">Pool Interfaces</a> 102</h4></div></div></div> 103<div class="toc"><dl class="toc"> 104<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces.pool">pool</a></span></dt> 105<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces.object_pool">Object_pool</a></span></dt> 106<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces.singleton_pool">Singleton_pool</a></span></dt> 107<dt><span class="section"><a href="interfaces.html#boost_pool.pool.interfaces.interfaces.pool_allocator">pool_allocator</a></span></dt> 108</dl></div> 109<div class="section"> 110<div class="titlepage"><div><div><h5 class="title"> 111<a name="boost_pool.pool.interfaces.interfaces.pool"></a><a class="link" href="interfaces.html#boost_pool.pool.interfaces.interfaces.pool" title="pool">pool</a> 112</h5></div></div></div> 113<p> 114 The <code class="computeroutput"><a class="link" href="../../boost/pool.html" title="Class template pool">pool</a></code> interface is a simple 115 Object Usage interface with Null Return. 116 </p> 117<p> 118 <code class="computeroutput"><a class="link" href="../../boost/pool.html" title="Class template pool">pool</a></code> is a fast memory allocator, 119 and guarantees proper alignment of all allocated chunks. 120 </p> 121<p> 122 <code class="computeroutput"><a class="link" href="../../header/boost/pool/pool_hpp.html" title="Header <boost/pool/pool.hpp>">pool.hpp</a></code> provides 123 two <a class="link" href="pooling.html#boost_pool.pool.pooling.user_allocator" title="The UserAllocator Concept">UserAllocator</a> 124 classes and a <code class="computeroutput"><a class="link" href="../../boost/pool.html" title="Class template pool">template class pool</a></code>, 125 which extends and generalizes the framework provided by the <a class="link" href="pooling.html#boost_pool.pool.pooling.simple" title="Simple Segregated Storage">Simple 126 Segregated Storage</a> solution. For information on other pool-based 127 interfaces, see the other <a class="link" href="interfaces.html" title="Boost Pool Interfaces - What interfaces are provided and when to use each one.">Pool 128 Interfaces</a>. 129 </p> 130<p> 131 <span class="bold"><strong>Synopsis</strong></span> 132 </p> 133<p> 134 There are two <a class="link" href="pooling.html#boost_pool.pool.pooling.user_allocator" title="The UserAllocator Concept">UserAllocator</a> 135 classes provided. Both of them are in <code class="computeroutput"><a class="link" href="../../header/boost/pool/pool_hpp.html" title="Header <boost/pool/pool.hpp>">pool.hpp</a></code>. 136 </p> 137<p> 138 The default value for the template parameter <a class="link" href="pooling.html#boost_pool.pool.pooling.user_allocator" title="The UserAllocator Concept">UserAllocator</a> 139 is always <code class="computeroutput"><span class="identifier">default_user_allocator_new_delete</span></code>. 140 </p> 141<p> 142</p> 143<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">default_user_allocator_new_delete</span> 144<span class="special">{</span> 145 <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size_type</span><span class="special">;</span> 146 <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ptrdiff_t</span> <span class="identifier">difference_type</span><span class="special">;</span> 147 148 <span class="keyword">static</span> <span class="keyword">char</span> <span class="special">*</span> <span class="identifier">malloc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">size_type</span> <span class="identifier">bytes</span><span class="special">)</span> 149 <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">new</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">nothrow</span><span class="special">)</span> <span class="keyword">char</span><span class="special">[</span><span class="identifier">bytes</span><span class="special">];</span> <span class="special">}</span> 150 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">free</span><span class="special">(</span><span class="keyword">char</span> <span class="special">*</span> <span class="keyword">const</span> <span class="identifier">block</span><span class="special">)</span> 151 <span class="special">{</span> <span class="keyword">delete</span> <span class="special">[]</span> <span class="identifier">block</span><span class="special">;</span> <span class="special">}</span> 152<span class="special">};</span> 153 154<span class="keyword">struct</span> <span class="identifier">default_user_allocator_malloc_free</span> 155<span class="special">{</span> 156 <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size_type</span><span class="special">;</span> 157 <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ptrdiff_t</span> <span class="identifier">difference_type</span><span class="special">;</span> 158 159 <span class="keyword">static</span> <span class="keyword">char</span> <span class="special">*</span> <span class="identifier">malloc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">size_type</span> <span class="identifier">bytes</span><span class="special">)</span> 160 <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">reinterpret_cast</span><span class="special"><</span><span class="keyword">char</span> <span class="special">*>(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">malloc</span><span class="special">(</span><span class="identifier">bytes</span><span class="special">));</span> <span class="special">}</span> 161 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">free</span><span class="special">(</span><span class="keyword">char</span> <span class="special">*</span> <span class="keyword">const</span> <span class="identifier">block</span><span class="special">)</span> 162 <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">free</span><span class="special">(</span><span class="identifier">block</span><span class="special">);</span> <span class="special">}</span> 163<span class="special">};</span> 164 165<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">UserAllocator</span> <span class="special">=</span> <span class="identifier">default_user_allocator_new_delete</span><span class="special">></span> 166<span class="keyword">class</span> <span class="identifier">pool</span> 167<span class="special">{</span> 168 <span class="keyword">private</span><span class="special">:</span> 169 <span class="identifier">pool</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pool</span> <span class="special">&);</span> 170 <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">pool</span> <span class="special">&);</span> 171 172 <span class="keyword">public</span><span class="special">:</span> 173 <span class="keyword">typedef</span> <span class="identifier">UserAllocator</span> <span class="identifier">user_allocator</span><span class="special">;</span> 174 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">UserAllocator</span><span class="special">::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span> 175 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">UserAllocator</span><span class="special">::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span> 176 177 <span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span><span class="identifier">size_type</span> <span class="identifier">requested_size</span><span class="special">);</span> 178 <span class="special">~</span><span class="identifier">pool</span><span class="special">();</span> 179 180 <span class="keyword">bool</span> <span class="identifier">release_memory</span><span class="special">();</span> 181 <span class="keyword">bool</span> <span class="identifier">purge_memory</span><span class="special">();</span> 182 183 <span class="keyword">bool</span> <span class="identifier">is_from</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">chunk</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 184 <span class="identifier">size_type</span> <span class="identifier">get_requested_size</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 185 186 <span class="keyword">void</span> <span class="special">*</span> <span class="identifier">malloc</span><span class="special">();</span> 187 <span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ordered_malloc</span><span class="special">();</span> 188 <span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ordered_malloc</span><span class="special">(</span><span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 189 190 <span class="keyword">void</span> <span class="identifier">free</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">chunk</span><span class="special">);</span> 191 <span class="keyword">void</span> <span class="identifier">ordered_free</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">chunk</span><span class="special">);</span> 192 <span class="keyword">void</span> <span class="identifier">free</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">chunks</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 193 <span class="keyword">void</span> <span class="identifier">ordered_free</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">chunks</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 194<span class="special">};</span> 195</pre> 196<p> 197 </p> 198<p> 199 <span class="bold"><strong>Example:</strong></span> 200</p> 201<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">func</span><span class="special">()</span> 202<span class="special">{</span> 203 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><></span> <span class="identifier">p</span><span class="special">(</span><span class="keyword">sizeof</span><span class="special">(</span><span class="keyword">int</span><span class="special">));</span> 204 <span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> 205 <span class="special">{</span> 206 <span class="keyword">int</span> <span class="special">*</span> <span class="keyword">const</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">malloc</span><span class="special">();</span> 207 <span class="special">...</span> <span class="comment">// Do something with t; don't take the time to free() it.</span> 208 <span class="special">}</span> 209<span class="special">}</span> <span class="comment">// on function exit, p is destroyed, and all malloc()'ed ints are implicitly freed.</span> 210</pre> 211<p> 212 </p> 213</div> 214<div class="section"> 215<div class="titlepage"><div><div><h5 class="title"> 216<a name="boost_pool.pool.interfaces.interfaces.object_pool"></a><a class="link" href="interfaces.html#boost_pool.pool.interfaces.interfaces.object_pool" title="Object_pool">Object_pool</a> 217</h5></div></div></div> 218<p> 219 The <code class="computeroutput"><a class="link" href="../../boost/object_pool.html" title="Class template object_pool">template class object_pool</a></code> 220 interface is an Object Usage interface with Null Return, but is aware 221 of the type of the object for which it is allocating chunks. On destruction, 222 any chunks that have been allocated from that <code class="computeroutput"><span class="identifier">object_pool</span></code> 223 will have their destructors called. 224 </p> 225<p> 226 <code class="computeroutput"><a class="link" href="../../header/boost/pool/object_pool_hpp.html" title="Header <boost/pool/object_pool.hpp>">object_pool.hpp</a></code> 227 provides a template type that can be used for fast and efficient memory 228 allocation. It also provides automatic destruction of non-deallocated 229 objects. 230 </p> 231<p> 232 For information on other pool-based interfaces, see the other <a class="link" href="interfaces.html" title="Boost Pool Interfaces - What interfaces are provided and when to use each one.">Pool 233 Interfaces</a>. 234 </p> 235<p> 236 <span class="bold"><strong>Synopsis</strong></span> 237 </p> 238<p> 239</p> 240<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">ElementType</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">UserAllocator</span> <span class="special">=</span> <span class="identifier">default_user_allocator_new_delete</span><span class="special">></span> 241<span class="keyword">class</span> <span class="identifier">object_pool</span> 242<span class="special">{</span> 243 <span class="keyword">private</span><span class="special">:</span> 244 <span class="identifier">object_pool</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">object_pool</span> <span class="special">&);</span> 245 <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">object_pool</span> <span class="special">&);</span> 246 247 <span class="keyword">public</span><span class="special">:</span> 248 <span class="keyword">typedef</span> <span class="identifier">ElementType</span> <span class="identifier">element_type</span><span class="special">;</span> 249 <span class="keyword">typedef</span> <span class="identifier">UserAllocator</span> <span class="identifier">user_allocator</span><span class="special">;</span> 250 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">UserAllocator</span><span class="special">>::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span> 251 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">UserAllocator</span><span class="special">>::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span> 252 253 <span class="identifier">object_pool</span><span class="special">();</span> 254 <span class="special">~</span><span class="identifier">object_pool</span><span class="special">();</span> 255 256 <span class="identifier">element_type</span> <span class="special">*</span> <span class="identifier">malloc</span><span class="special">();</span> 257 <span class="keyword">void</span> <span class="identifier">free</span><span class="special">(</span><span class="identifier">element_type</span> <span class="special">*</span> <span class="identifier">p</span><span class="special">);</span> 258 <span class="keyword">bool</span> <span class="identifier">is_from</span><span class="special">(</span><span class="identifier">element_type</span> <span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 259 260 <span class="identifier">element_type</span> <span class="special">*</span> <span class="identifier">construct</span><span class="special">();</span> 261 <span class="comment">// other construct() functions</span> 262 <span class="keyword">void</span> <span class="identifier">destroy</span><span class="special">(</span><span class="identifier">element_type</span> <span class="special">*</span> <span class="identifier">p</span><span class="special">);</span> 263<span class="special">};</span> 264</pre> 265<p> 266 <span class="bold"><strong>Template Parameters</strong></span> 267 </p> 268<p> 269 <span class="emphasis"><em>ElementType</em></span> 270 </p> 271<p> 272 The template parameter is the type of object to allocate/deallocate. 273 It must have a non-throwing destructor. 274 </p> 275<p> 276 <span class="emphasis"><em>UserAllocator</em></span> 277 </p> 278<p> 279 Defines the method that the underlying Pool will use to allocate memory 280 from the system. Default is default_user_allocator_new_delete. See __<a class="link" href="pooling.html#boost_pool.pool.pooling.user_allocator" title="The UserAllocator Concept">UserAllocator</a> 281 for details. 282 </p> 283<p> 284 <span class="bold"><strong>Example:</strong></span> struct X { ... }; // has destructor 285 with side-effects. 286 </p> 287<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">func</span><span class="special">()</span> 288<span class="special">{</span> 289 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">object_pool</span><span class="special"><</span><span class="identifier">X</span><span class="special">></span> <span class="identifier">p</span><span class="special">;</span> 290 <span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> 291 <span class="special">{</span> 292 <span class="identifier">X</span> <span class="special">*</span> <span class="keyword">const</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">malloc</span><span class="special">();</span> 293 <span class="special">...</span> <span class="comment">// Do something with t; don't take the time to free() it.</span> 294 <span class="special">}</span> 295<span class="special">}</span> <span class="comment">// on function exit, p is destroyed, and all destructors for the X objects are called.</span> 296</pre> 297</div> 298<div class="section"> 299<div class="titlepage"><div><div><h5 class="title"> 300<a name="boost_pool.pool.interfaces.interfaces.singleton_pool"></a><a class="link" href="interfaces.html#boost_pool.pool.interfaces.interfaces.singleton_pool" title="Singleton_pool">Singleton_pool</a> 301</h5></div></div></div> 302<p> 303 The <code class="computeroutput"><a class="link" href="../../boost/singleton_pool.html" title="Class template singleton_pool">singleton_pool interface</a></code> 304 at <code class="computeroutput"><a class="link" href="../../header/boost/pool/singleton_pool_hpp.html" title="Header <boost/pool/singleton_pool.hpp>">singleton_pool.hpp</a></code> 305 is a Singleton Usage interface with Null Return. It's just the same as 306 the pool interface but with Singleton Usage instead. 307 </p> 308<p> 309 <span class="bold"><strong>Synopsis</strong></span> 310 </p> 311<p> 312</p> 313<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Tag</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">RequestedSize</span><span class="special">,</span> 314 <span class="keyword">typename</span> <span class="identifier">UserAllocator</span> <span class="special">=</span> <span class="identifier">default_user_allocator_new_delete</span><span class="special">></span> 315<span class="keyword">struct</span> <span class="identifier">singleton_pool</span> 316<span class="special">{</span> 317 <span class="keyword">public</span><span class="special">:</span> 318 <span class="keyword">typedef</span> <span class="identifier">Tag</span> <span class="identifier">tag</span><span class="special">;</span> 319 <span class="keyword">typedef</span> <span class="identifier">UserAllocator</span> <span class="identifier">user_allocator</span><span class="special">;</span> 320 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">UserAllocator</span><span class="special">>::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span> 321 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">UserAllocator</span><span class="special">>::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span> 322 323 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="identifier">requested_size</span> <span class="special">=</span> <span class="identifier">RequestedSize</span><span class="special">;</span> 324 325 <span class="keyword">private</span><span class="special">:</span> 326 <span class="keyword">static</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">size_type</span><span class="special">></span> <span class="identifier">p</span><span class="special">;</span> <span class="comment">// exposition only!</span> 327 328 <span class="identifier">singleton_pool</span><span class="special">();</span> 329 330 <span class="keyword">public</span><span class="special">:</span> 331 <span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">is_from</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ptr</span><span class="special">);</span> 332 333 <span class="keyword">static</span> <span class="keyword">void</span> <span class="special">*</span> <span class="identifier">malloc</span><span class="special">();</span> 334 <span class="keyword">static</span> <span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ordered_malloc</span><span class="special">();</span> 335 <span class="keyword">static</span> <span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ordered_malloc</span><span class="special">(</span><span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 336 337 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">free</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ptr</span><span class="special">);</span> 338 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">ordered_free</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ptr</span><span class="special">);</span> 339 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">free</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ptr</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">n</span><span class="special">);</span> 340 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">ordered_free</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> <span class="identifier">ptr</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 341 342 <span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">release_memory</span><span class="special">();</span> 343 <span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">purge_memory</span><span class="special">();</span> 344<span class="special">};</span> 345</pre> 346<p> 347 <span class="bold"><strong>Notes</strong></span> 348 </p> 349<p> 350 The underlying pool <code class="computeroutput"><span class="identifier">p</span></code> 351 referenced by the static functions in <code class="computeroutput"><span class="identifier">singleton_pool</span></code> 352 is actually declared in a way so that it is: 353 </p> 354<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 355<li class="listitem"> 356 Thread-safe if there is only one thread running before <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code> 357 begins and after <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code> ends. All of the static functions 358 of singleton_pool synchronize their access to <code class="computeroutput"><span class="identifier">p</span></code>. 359 </li> 360<li class="listitem"> 361 Guaranteed to be constructed before it is used, so that the simple 362 static object in the synopsis above would actually be an incorrect 363 implementation. The actual implementation to guarantee this is considerably 364 more complicated. 365 </li> 366</ul></div> 367<p> 368 <span class="bold"><strong>Note</strong></span> that a different underlying pool 369 <code class="computeroutput"><span class="identifier">p</span></code> exists for each different 370 set of template parameters, including implementation-specific ones. 371 </p> 372<p> 373 <span class="bold"><strong>Template Parameters</strong></span> 374 </p> 375<p> 376 <span class="emphasis"><em>Tag</em></span> 377 </p> 378<p> 379 The <span class="emphasis"><em>Tag</em></span> template parameter allows different unbounded 380 sets of singleton pools to exist. For example, the pool allocators use 381 two tag classes to ensure that the two different allocator types never 382 share the same underlying singleton pool. 383 </p> 384<p> 385 <span class="emphasis"><em>Tag</em></span> is never actually used by <code class="computeroutput"><span class="identifier">singleton_pool</span></code>. 386 </p> 387<p> 388 <span class="emphasis"><em>RequestedSize</em></span> The requested size of memory chunks 389 to allocate. This is passed as a constructor parameter to the underlying 390 pool. Must be greater than 0. 391 </p> 392<p> 393 <span class="emphasis"><em>UserAllocator</em></span> 394 </p> 395<p> 396 Defines the method that the underlying pool will use to allocate memory 397 from the system. See User Allocators for details. 398 </p> 399<p> 400 <span class="bold"><strong>Example:</strong></span> struct MyPoolTag { }; 401 </p> 402<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">singleton_pool</span><span class="special"><</span><span class="identifier">MyPoolTag</span><span class="special">,</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="keyword">int</span><span class="special">)></span> <span class="identifier">my_pool</span><span class="special">;</span> 403<span class="keyword">void</span> <span class="identifier">func</span><span class="special">()</span> 404<span class="special">{</span> 405 <span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> 406 <span class="special">{</span> 407 <span class="keyword">int</span> <span class="special">*</span> <span class="keyword">const</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">my_pool</span><span class="special">::</span><span class="identifier">malloc</span><span class="special">();</span> 408 <span class="special">...</span> <span class="comment">// Do something with t; don't take the time to free() it.</span> 409 <span class="special">}</span> 410 <span class="comment">// Explicitly free all malloc()'ed ints.</span> 411 <span class="identifier">my_pool</span><span class="special">::</span><span class="identifier">purge_memory</span><span class="special">();</span> 412<span class="special">}</span> 413</pre> 414</div> 415<div class="section"> 416<div class="titlepage"><div><div><h5 class="title"> 417<a name="boost_pool.pool.interfaces.interfaces.pool_allocator"></a><a class="link" href="interfaces.html#boost_pool.pool.interfaces.interfaces.pool_allocator" title="pool_allocator">pool_allocator</a> 418</h5></div></div></div> 419<p> 420 The <code class="computeroutput"><a class="link" href="../../boost/pool_allocator.html" title="Class template pool_allocator">pool_allocator interface</a></code> 421 is a Singleton Usage interface with Exceptions. It is built on the singleton_pool 422 interface, and provides a Standard Allocator-compliant class (for use 423 in containers, etc.). 424 </p> 425<p> 426 <span class="bold"><strong>Introduction</strong></span> 427 </p> 428<p> 429 <code class="computeroutput"><a class="link" href="../../header/boost/pool/pool_alloc_hpp.html" title="Header <boost/pool/pool_alloc.hpp>">pool_alloc.hpp</a></code> 430 </p> 431<p> 432 Provides two template types that can be used for fast and efficient memory 433 allocation. These types both satisfy the Standard Allocator requirements 434 [20.1.5] and the additional requirements in [20.1.5/4], so they can be 435 used with Standard or user-supplied containers. 436 </p> 437<p> 438 For information on other pool-based interfaces, see the other <a class="link" href="interfaces.html" title="Boost Pool Interfaces - What interfaces are provided and when to use each one.">Pool 439 Interfaces</a>. 440 </p> 441<p> 442 <span class="bold"><strong>Synopsis</strong></span> 443 </p> 444<p> 445</p> 446<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">pool_allocator_tag</span> <span class="special">{</span> <span class="special">};</span> 447 448<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">,</span> 449 <span class="keyword">typename</span> <span class="identifier">UserAllocator</span> <span class="special">=</span> <span class="identifier">default_user_allocator_new_delete</span><span class="special">></span> 450<span class="keyword">class</span> <span class="identifier">pool_allocator</span> 451<span class="special">{</span> 452 <span class="keyword">public</span><span class="special">:</span> 453 <span class="keyword">typedef</span> <span class="identifier">UserAllocator</span> <span class="identifier">user_allocator</span><span class="special">;</span> 454 <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">value_type</span><span class="special">;</span> 455 <span class="keyword">typedef</span> <span class="identifier">value_type</span> <span class="special">*</span> <span class="identifier">pointer</span><span class="special">;</span> 456 <span class="keyword">typedef</span> <span class="keyword">const</span> <span class="identifier">value_type</span> <span class="special">*</span> <span class="identifier">const_pointer</span><span class="special">;</span> 457 <span class="keyword">typedef</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">reference</span><span class="special">;</span> 458 <span class="keyword">typedef</span> <span class="keyword">const</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">const_reference</span><span class="special">;</span> 459 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">UserAllocator</span><span class="special">>::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span> 460 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">UserAllcoator</span><span class="special">>::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span> 461 462 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">U</span><span class="special">></span> 463 <span class="keyword">struct</span> <span class="identifier">rebind</span> 464 <span class="special">{</span> <span class="keyword">typedef</span> <span class="identifier">pool_allocator</span><span class="special"><</span><span class="identifier">U</span><span class="special">,</span> <span class="identifier">UserAllocator</span><span class="special">></span> <span class="identifier">other</span><span class="special">;</span> <span class="special">};</span> 465 466 <span class="keyword">public</span><span class="special">:</span> 467 <span class="identifier">pool_allocator</span><span class="special">();</span> 468 <span class="identifier">pool_allocator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pool_allocator</span> <span class="special">&);</span> 469 <span class="comment">// The following is not explicit, mimicking std::allocator [20.4.1]</span> 470 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">U</span><span class="special">></span> 471 <span class="identifier">pool_allocator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pool_allocator</span><span class="special"><</span><span class="identifier">U</span><span class="special">,</span> <span class="identifier">UserAllocator</span><span class="special">></span> <span class="special">&);</span> 472 <span class="identifier">pool_allocator</span> <span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">pool_allocator</span> <span class="special">&);</span> 473 <span class="special">~</span><span class="identifier">pool_allocator</span><span class="special">();</span> 474 475 <span class="keyword">static</span> <span class="identifier">pointer</span> <span class="identifier">address</span><span class="special">(</span><span class="identifier">reference</span> <span class="identifier">r</span><span class="special">);</span> 476 <span class="keyword">static</span> <span class="identifier">const_pointer</span> <span class="identifier">address</span><span class="special">(</span><span class="identifier">const_reference</span> <span class="identifier">s</span><span class="special">);</span> 477 <span class="keyword">static</span> <span class="identifier">size_type</span> <span class="identifier">max_size</span><span class="special">();</span> 478 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">construct</span><span class="special">(</span><span class="identifier">pointer</span> <span class="identifier">ptr</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">t</span><span class="special">);</span> 479 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">destroy</span><span class="special">(</span><span class="identifier">pointer</span> <span class="identifier">ptr</span><span class="special">);</span> 480 481 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">pool_allocator</span> <span class="special">&)</span> <span class="keyword">const</span><span class="special">;</span> 482 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">pool_allocator</span> <span class="special">&)</span> <span class="keyword">const</span><span class="special">;</span> 483 484 <span class="keyword">static</span> <span class="identifier">pointer</span> <span class="identifier">allocate</span><span class="special">(</span><span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 485 <span class="keyword">static</span> <span class="identifier">pointer</span> <span class="identifier">allocate</span><span class="special">(</span><span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">pointer</span><span class="special">);</span> 486 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span><span class="identifier">pointer</span> <span class="identifier">ptr</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 487<span class="special">};</span> 488 489<span class="keyword">struct</span> <span class="identifier">fast_pool_allocator_tag</span> <span class="special">{</span> <span class="special">};</span> 490 491<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span> 492 <span class="keyword">typename</span> <span class="identifier">UserAllocator</span> <span class="special">=</span> <span class="identifier">default_user_allocator_new_delete</span><span class="special">></span> 493<span class="keyword">class</span> <span class="identifier">fast_pool_allocator</span> 494<span class="special">{</span> 495 <span class="keyword">public</span><span class="special">:</span> 496 <span class="keyword">typedef</span> <span class="identifier">UserAllocator</span> <span class="identifier">user_allocator</span><span class="special">;</span> 497 <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">value_type</span><span class="special">;</span> 498 <span class="keyword">typedef</span> <span class="identifier">value_type</span> <span class="special">*</span> <span class="identifier">pointer</span><span class="special">;</span> 499 <span class="keyword">typedef</span> <span class="keyword">const</span> <span class="identifier">value_type</span> <span class="special">*</span> <span class="identifier">const_pointer</span><span class="special">;</span> 500 <span class="keyword">typedef</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">reference</span><span class="special">;</span> 501 <span class="keyword">typedef</span> <span class="keyword">const</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">const_reference</span><span class="special">;</span> 502 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">UserAllocator</span><span class="special">>::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span> 503 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">pool</span><span class="special"><</span><span class="identifier">UserAllocator</span><span class="special">>::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span> 504 505 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">U</span><span class="special">></span> 506 <span class="keyword">struct</span> <span class="identifier">rebind</span> 507 <span class="special">{</span> <span class="keyword">typedef</span> <span class="identifier">fast_pool_allocator</span><span class="special"><</span><span class="identifier">U</span><span class="special">,</span> <span class="identifier">UserAllocator</span><span class="special">></span> <span class="identifier">other</span><span class="special">;</span> <span class="special">};</span> 508 509 <span class="keyword">public</span><span class="special">:</span> 510 <span class="identifier">fast_pool_allocator</span><span class="special">();</span> 511 <span class="identifier">fast_pool_allocator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">fast_pool_allocator</span> <span class="special">&);</span> 512 <span class="comment">// The following is not explicit, mimicking std::allocator [20.4.1]</span> 513 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">U</span><span class="special">></span> 514 <span class="identifier">fast_pool_allocator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">fast_pool_allocator</span><span class="special"><</span><span class="identifier">U</span><span class="special">,</span> <span class="identifier">UserAllocator</span><span class="special">></span> <span class="special">&);</span> 515 <span class="identifier">fast_pool_allocator</span> <span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">fast_pool_allocator</span> <span class="special">&);</span> 516 <span class="special">~</span><span class="identifier">fast_pool_allocator</span><span class="special">();</span> 517 518 <span class="keyword">static</span> <span class="identifier">pointer</span> <span class="identifier">address</span><span class="special">(</span><span class="identifier">reference</span> <span class="identifier">r</span><span class="special">);</span> 519 <span class="keyword">static</span> <span class="identifier">const_pointer</span> <span class="identifier">address</span><span class="special">(</span><span class="identifier">const_reference</span> <span class="identifier">s</span><span class="special">);</span> 520 <span class="keyword">static</span> <span class="identifier">size_type</span> <span class="identifier">max_size</span><span class="special">();</span> 521 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">construct</span><span class="special">(</span><span class="identifier">pointer</span> <span class="identifier">ptr</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">t</span><span class="special">);</span> 522 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">destroy</span><span class="special">(</span><span class="identifier">pointer</span> <span class="identifier">ptr</span><span class="special">);</span> 523 524 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">fast_pool_allocator</span> <span class="special">&)</span> <span class="keyword">const</span><span class="special">;</span> 525 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">fast_pool_allocator</span> <span class="special">&)</span> <span class="keyword">const</span><span class="special">;</span> 526 527 <span class="keyword">static</span> <span class="identifier">pointer</span> <span class="identifier">allocate</span><span class="special">(</span><span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 528 <span class="keyword">static</span> <span class="identifier">pointer</span> <span class="identifier">allocate</span><span class="special">(</span><span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">pointer</span><span class="special">);</span> 529 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span><span class="identifier">pointer</span> <span class="identifier">ptr</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="identifier">n</span><span class="special">);</span> 530 531 <span class="keyword">static</span> <span class="identifier">pointer</span> <span class="identifier">allocate</span><span class="special">();</span> 532 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span><span class="identifier">pointer</span> <span class="identifier">ptr</span><span class="special">);</span> 533<span class="special">};</span> 534</pre> 535<p> 536 <span class="bold"><strong>Template Parameters</strong></span> 537 </p> 538<p> 539 <span class="emphasis"><em>T</em></span> The first template parameter is the type of object 540 to allocate/deallocate. 541 </p> 542<p> 543 <span class="emphasis"><em>UserAllocator</em></span> Defines the method that the underlying 544 Pool will use to allocate memory from the system. See User Allocators 545 for details. 546 </p> 547<p> 548 <span class="bold"><strong>Example:</strong></span> 549 </p> 550<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">func</span><span class="special">()</span> 551<span class="special">{</span> 552 <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pool_allocator</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="special">></span> <span class="identifier">v</span><span class="special">;</span> 553 <span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> 554 <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">13</span><span class="special">);</span> 555<span class="special">}</span> <span class="comment">// Exiting the function does NOT free the system memory allocated by the pool allocator.</span> 556 <span class="comment">// You must call</span> 557 <span class="comment">// boost::singleton_pool<boost::pool_allocator_tag, sizeof(int)>::release_memory();</span> 558 <span class="comment">// in order to force freeing the system memory.</span> 559</pre> 560</div> 561</div> 562</div> 563<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 564<td align="left"></td> 565<td align="right"><div class="copyright-footer">Copyright © 2000-2006 Stephen Cleary<br>Copyright © 2011 Paul A. Bristow<p> 566 Distributed under the Boost Software License, Version 1.0. (See accompanying 567 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 568 </p> 569</div></td> 570</tr></table> 571<hr> 572<div class="spirit-nav"> 573<a accesskey="p" href="testing.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pool.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="pooling.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 574</div> 575</body> 576</html> 577