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
|
<!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>Pool</title>
</head>
<body>
<img src="../../../../boost.png" width="276" height="86" alt="C++ Boost">
<h1 align="center">User Allocators</h1>
<h2>Introduction</h2>
<p>Pool objects need to request memory blocks from the system, which the
Pool then splits into chunks to allocate to the user. By specifying a
<span class="code">UserAllocator</span> template parameter to various Pool
interfaces, users can control how those system memory blocks are
allocated.</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">UserAllocator</td>
<td>A User Allocator type</td>
</tr>
<tr>
<td class="code">block</td>
<td>value of type <span class="code">char *</span></td>
</tr>
<tr>
<td class="code">n</td>
<td>value of type <span class=
"code">UserAllocator::size_type</span></td>
</tr>
</table><br>
<table border align="center" summary="">
<caption>
<em>Typedefs</em>
</caption>
<tr>
<th>Expression</th>
<th>Type</th>
</tr>
<tr>
<td class="code">UserAllocator::size_type</td>
<td>An unsigned integral type that can represent the size of the
largest object to be allocated</td>
</tr>
<tr>
<td class="code">UserAllocator::difference_type</td>
<td>A signed integral type that can represent the difference of any two
pointers</td>
</tr>
</table><br>
<table border align="center" summary="">
<caption>
<em>Allocation and Deallocation</em>
</caption>
<tr>
<th>Expression</th>
<th>Return Type</th>
<th>Pre-Condition/Notes</th>
</tr>
<tr>
<td class="code">UserAllocator::malloc(n)</td>
<td class="code">char *</td>
<td>Attempts to allocate <span class="code">n</span> bytes from the
system. Returns 0 if out-of-memory.</td>
</tr>
<tr>
<td class="code">UserAllocator::free(block)</td>
<td class="code">void</td>
<td><span class="code">block</span> must have been previously returned
from a call to <span class="code">UserAllocator::malloc</span>.</td>
</tr>
</table>
<h2>Provided Implementations</h2>
<p>There are two <span class="code">UserAllocator</span> classes provided.
Both of them are in pool.hpp (see <a href="pool.html">pool</a>). The
default value for the template parameter <span class=
"code">UserAllocator</span> is always <span class=
"code">default_user_allocator_new_delete</span>.</p>
<h3>Synopsis</h3>
<pre class="code">
struct default_user_allocator_new_delete
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
static char * malloc(const size_type bytes)
{ return new (std::nothrow) char[bytes]; }
static void free(char * const block)
{ delete [] block; }
};
struct default_user_allocator_malloc_free
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
static char * malloc(const size_type bytes)
{ return reinterpret_cast<char *>(std::malloc(bytes)); }
static void free(char * const block)
{ std::free(block); }
};
</pre>
<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>
|