File: object_pool.html

package info (click to toggle)
boost 1.34.1-14
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 116,412 kB
  • ctags: 259,566
  • sloc: cpp: 642,395; xml: 56,450; python: 17,612; ansic: 14,520; sh: 2,265; yacc: 858; perl: 481; makefile: 478; lex: 94; sql: 74; csh: 6
file content (287 lines) | stat: -rw-r--r-- 7,602 bytes parent folder | download | duplicates (2)
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
<!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>object_pool - Boost Object Pool Allocator</title>
</head>

<body>
  <img src="../../../../boost.png" width="276" height="86" alt="C++ Boost">

  <h1 align="center">object_pool - Boost Object Pool Allocator</h1>

  <h2>Introduction</h2>

  <p>object_pool.hpp provides a template type that can be used for fast and 
  efficient memory allocation. It also provides automatic destruction of 
  non-deallocated objects. For information on other pool-based interfaces, see <a href="../interfaces.html">
  the other pool interfaces</a>.</p>

  <h2>Synopsis</h2>
  <pre class="code">
template &lt;typename ElementType, typename UserAllocator = default_user_allocator_new_delete&gt;
class object_pool
{
  private:
    object_pool(const object_pool &amp;);
    void operator=(const object_pool &amp;);

  public:
    typedef ElementType element_type;
    typedef UserAllocator user_allocator;
    typedef typename pool&lt;UserAllocator&gt;::size_type size_type;
    typedef typename pool&lt;UserAllocator&gt;::difference_type difference_type;

    object_pool();
    ~object_pool();

    element_type * malloc();
    void free(element_type * p);
    bool is_from(element_type * p) const;

    element_type * construct();
    // other construct() functions
    void destroy(element_type * p);
};
</pre>

  <h2>Template Parameters</h2>

  <h3>ElementType</h3>

  <p>The template parameter is the type of object to allocate/deallocate. It 
  must have a non-throwing destructor.</p>

  <h3>UserAllocator</h3>

  <p>Defines the method that the underlying Pool 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">ObjectPool</td>

      <td><span class="code">object_pool&lt;ElementType, UserAllocator&gt;</span></td>
    </tr>

    <tr>
      <td class="code">t</td>

      <td>value of type <span class="code">ObjectPool</span></td>
    </tr>

    <tr>
      <td class="code">u</td>

      <td>value of type <span class="code">const ObjectPool</span></td>
    </tr>

    <tr>
      <td class="code">p</td>

      <td>value of type <span class="code">ElementType *</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">ObjectPool::element_type</td>

      <td class="code">ElementType</td>
    </tr>

    <tr>
      <td class="code">ObjectPool::user_allocator</td>

      <td class="code">UserAllocator</td>
    </tr>

    <tr>
      <td class="code">ObjectPool::size_type</td>

      <td class="code">pool&lt;UserAllocator&gt;::size_type</td>
    </tr>

    <tr>
      <td class="code">ObjectPool::difference_type</td>

      <td class="code">pool&lt;UserAllocator&gt;::difference_type</td>
    </tr>
  </table><br>

  <table border align="center" summary="">
    <caption>
      <em>Constructors, Destructors, and Testing</em>
    </caption>

    <tr>
      <th>Expression</th>

      <th>Return Type</th>

      <th>Notes</th>
    </tr>

    <tr>
      <td class="code">ObjectPool()</td>

      <td>not used</td>

      <td>Constructs a new empty <span class="code">ObjectPool</span></td>
    </tr>

    <tr>
      <td class="code">(&amp;t)-&gt;~ObjectPool()</td>

      <td>not used</td>

      <td>Destructs the <span class="code">ObjectPool</span>; <span class=
      "code">~ElementType()</span> is called for each allocated ElementType 
      that has not been deallocated. O(N).</td>
    </tr>

    <tr>
      <td class="code">u.is_from(p)</td>

      <td class="code">bool</td>

      <td>Returns <span class="code">true</span> if <span class=
      "code">p</span> was allocated from <span class="code">u</span> or may be 
      returned as the result of a future allocation from <span class=
      "code">u</span>. Returns <span class="code">false</span> if
      <span class="code">p</span> was allocated from some other pool or may be 
      returned as the result of a future allocation from some other pool. 
      Otherwise, the return value is meaningless; note that this function may
      <strong>not</strong> be used to reliably test random pointer values.</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</th>

      <th>Semantic Equivalence</th>

      <th>Notes</th>
    </tr>

    <tr>
      <td class="code">t.malloc()</td>

      <td class="code">ElementType *</td>

      <td></td>

      <td></td>

      <td>Allocates memory that can hold an object of type <span class=
      "code">ElementType</span>. If out of memory, returns <span class=
      "code">0</span>. Amortized O(1).</td>
    </tr>

    <tr>
      <td class="code">t.free(p)</td>

      <td>not used</td>

      <td><span class="code">p</span> must have been previously allocated from <span class="code">
      t</span></td>

      <td></td>

      <td>Deallocates a chunk of memory. Note that <span class=
      "code">p</span> may not be <span class="code">0</span>. Note that the 
      destructor for <span class="code">p</span> is not called. O(N).</td>
    </tr>

    <tr>
      <td class="code">t.construct(???)</td>

      <td class="code">ElementType *</td>

      <td><span class="code">ElementType</span> must have a constructor 
      matching <span class="code">???</span>; the number of parameters given 
      must not exceed what is supported through <a href=
      "../implementation/pool_construct.html">pool_construct</a></td>

      <td></td>

      <td>Allocates and initializes an object of type <span class=
      "code">ElementType</span>. If out of memory, returns <span class=
      "code">0</span>. Amortized O(1).</td>
    </tr>

    <tr>
      <td class="code">t.destroy(p)</td>

      <td>not used</td>

      <td><span class="code">p</span> must have been previously allocated from <span class="code">
      t</span></td>

      <td class="code">p-&gt;~ElementType(); t.free(p);</td>

      <td></td>
    </tr>
  </table>

  <h2>Symbols</h2>

  <ul>
    <li>boost::object_pool</li>
  </ul>

  <h2><a href="../implementation/object_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 &copy; 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>