1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link href="../pool.css" rel="stylesheet" type="text/css">
<title>Singleton Pool</title>
</head>
<body>
<img src="../../../../boost.png" width="276" height="86" alt="C++ Boost">
<h1 align="center">Singleton Pool</h1>
<h2>Introduction</h2>
<p>singleton_pool.hpp provides a template class <span class=
"code">singleton_pool</span>, which provides access to a <span class=
"code">pool</span> as a singleton object. For information on other
pool-based interfaces, see <a href="../interfaces.html">the other pool
interfaces</a>.</p>
<h2>Synopsis</h2>
<pre class="code">
template <typename Tag, unsigned RequestedSize,
typename UserAllocator = default_user_allocator_new_delete>
struct singleton_pool
{
public:
typedef Tag tag;
typedef UserAllocator user_allocator;
typedef typename pool<UserAllocator>::size_type size_type;
typedef typename pool<UserAllocator>::difference_type difference_type;
static const unsigned requested_size = RequestedSize;
private:
static pool<size_type> p; // exposition only!
singleton_pool();
public:
static bool is_from(void * ptr);
static void * malloc();
static void * ordered_malloc();
static void * ordered_malloc(size_type n);
static void free(void * ptr);
static void ordered_free(void * ptr);
static void free(void * ptr, std::size_t n);
static void ordered_free(void * ptr, size_type n);
static bool release_memory();
static bool purge_memory();
};
</pre>
<h2>Notes</h2>
<p>The underlying pool <span class="code">p</span> referenced by the static
functions in <span class="code">singleton_pool</span> is actually declared
in a way that it is:</p>
<ul>
<li>Thread-safe if there is only one thread running before main() begins
and after main() ends -- all of the static functions of <span class=
"code">singleton_pool</span> synchronize their access to <span class=
"code">p</span>.</li>
<li>Guaranteed to be constructed before it is used -- thus, the simple
static object in the synopsis above would actually be an incorrect
implementation. The actual <a href=
"../implementation/singleton_pool.html">implementation</a> to guarantee
this is considerably more complicated.</li>
</ul>
<p>Note that a different underlying pool <span class="code">p</span> exists
for each different set of template parameters, including <a href=
"../implementation/singleton_pool.html">implementation-specific
ones</a>.</p>
<h2>Template Parameters</h2>
<h3>Tag</h3>
<p>The <span class="code">Tag</span> template parameter allows different
unbounded sets of singleton pools to exist. For example, the <a href=
"pool_alloc.html">pool allocators</a> use two tag classes to ensure that
the two different allocator types never share the same underlying singleton
pool.</p>
<p><span class="code">Tag</span> is never actually used by <span class=
"code">singleton_pool</span>.</p>
<h3>RequestedSize</h3>
<p>The requested size of memory chunks to allocate. This is passed as a
constructor parameter to the underlying <span class="code">pool</span>.
Must be greater than 0.</p>
<h3>UserAllocator</h3>
<p>Defines the method that the underlying <span class="code">pool</span>
will use to allocate memory from the system. See <a href=
"user_allocator.html">User Allocators</a> for details.</p>
<h2>Semantics</h2>
<table border align="center" summary="">
<caption>
<em>Symbol Table</em>
</caption>
<tr>
<th>Symbol</th>
<th>Meaning</th>
</tr>
<tr>
<td class="code">SingletonPool</td>
<td class="code">singleton_pool<Tag, RequestedSize,
UserAllocator></td>
</tr>
<tr>
<td class="code">chunk</td>
<td>value of type <span class="code">void *</span></td>
</tr>
<tr>
<td class="code">n</td>
<td>value of type <span class="code">size_type</span></td>
</tr>
</table><br>
<table border align="center" summary="">
<caption>
<em>Typedefs/Static Const Values</em>
</caption>
<tr>
<th>Expression</th>
<th>Type/Value</th>
</tr>
<tr>
<td class="code">SingletonPool::tag</td>
<td class="code">Tag</td>
</tr>
<tr>
<td class="code">SingletonPool::user_allocator</td>
<td class="code">UserAllocator</td>
</tr>
<tr>
<td class="code">SingletonPool::size_type</td>
<td class="code">pool<UserAllocator>::size_type</td>
</tr>
<tr>
<td class="code">SingletonPool::difference_type</td>
<td class="code">pool<UserAllocator>::difference_type</td>
</tr>
<tr>
<td class="code">SingletonPool::requested_size</td>
<td class="code">RequestedSize</td>
</tr>
</table><br>
<table border align="center" summary="">
<caption>
<em>Functions</em>
</caption>
<tr>
<th>Expression</th>
<th>Return Type</th>
<th>Semantic Equivalent</th>
</tr>
<tr>
<td class="code">SingletonPool::is_from(chunk)</td>
<td class="code">bool</td>
<td><span class="code">SingletonPool::p.is_from(chunk);</span>
synchronized</td>
</tr>
<tr>
<td class="code">SingletonPool::malloc()</td>
<td class="code">void *</td>
<td><span class="code">SingletonPool::p.malloc();</span>
synchronized</td>
</tr>
<tr>
<td class="code">SingletonPool::ordered_malloc(n)</td>
<td class="code">void *</td>
<td><span class="code">SingletonPool::p.ordered_malloc(n);</span>
synchronized</td>
</tr>
<tr>
<td class="code">SingletonPool::free(chunk)</td>
<td class="code">void</td>
<td><span class="code">SingletonPool::p.free(chunk);</span>
synchronized</td>
</tr>
<tr>
<td class="code">SingletonPool::ordered_free(chunk)</td>
<td class="code">void</td>
<td><span class="code">SingletonPool::p.ordered_free(chunk);</span>
synchronized</td>
</tr>
<tr>
<td class="code">SingletonPool::free(chunk, n)</td>
<td class="code">void</td>
<td><span class="code">SingletonPool::p.free(chunk, n);</span>
synchronized</td>
</tr>
<tr>
<td class="code">SingletonPool::ordered_free(chunk, n)</td>
<td class="code">void</td>
<td><span class="code">SingletonPool::p.ordered_free(chunk, n);</span>
synchronized</td>
</tr>
<tr>
<td class="code">SingletonPool::release_memory()</td>
<td class="code">bool</td>
<td><span class="code">SingletonPool::p.release_memory();</span>
synchronized</td>
</tr>
<tr>
<td class="code">SingletonPool::purge_memory()</td>
<td class="code">bool</td>
<td><span class="code">SingletonPool::p.purge_memory();</span>
synchronized</td>
</tr>
</table>
<p>For more information on the semantics of these functions, see the
<a href="pool.html">pool interface</a>.</p>
<h2>Symbols</h2>
<ul>
<li>boost::singleton_pool</li>
</ul>
<h2><a href="../implementation/singleton_pool.html">Implementation
Details</a></h2>
<hr>
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05 December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p>
<p><i>Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
or copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body>
</html>
|