File: a00056.html

package info (click to toggle)
libloki 0.1.7-4
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 6,568 kB
  • sloc: cpp: 30,476; ansic: 1,974; makefile: 365; php: 316; perl: 108
file content (305 lines) | stat: -rwxr-xr-x 16,848 bytes parent folder | download | duplicates (5)
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Loki: Loki::FixedAllocator Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    <li>
      <form action="search.php" method="get">
        <table cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
            <td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
          </tr>
        </table>
      </form>
    </li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="classes.html"><span>Class&nbsp;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="a00192.html">Loki</a>::<a class="el" href="a00056.html">FixedAllocator</a>
  </div>
</div>
<div class="contents">
<h1>Loki::FixedAllocator Class Reference<br>
<small>
[<a class="el" href="a00217.html">Internals</a>]</small>
</h1><!-- doxytag: class="Loki::FixedAllocator" --><div class="dynheader">
Collaboration diagram for Loki::FixedAllocator:</div>
<div class="dynsection">
<center><font size="2">[<a target="top" href="graph_legend.html">legend</a>]</font></center></div>

<p>
<a href="a00450.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ce7ad725a2f44c427641f4ce629a3aac"></a><!-- doxytag: member="Loki::FixedAllocator::FixedAllocator" ref="ce7ad725a2f44c427641f4ce629a3aac" args="()" -->
&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#ce7ad725a2f44c427641f4ce629a3aac">FixedAllocator</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Create a <a class="el" href="a00056.html">FixedAllocator</a> which manages blocks of 'blockSize' size. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="080589e92d310aeb4e432d195bcd7ba5"></a><!-- doxytag: member="Loki::FixedAllocator::~FixedAllocator" ref="080589e92d310aeb4e432d195bcd7ba5" args="()" -->
&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#080589e92d310aeb4e432d195bcd7ba5">~FixedAllocator</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destroy the <a class="el" href="a00056.html">FixedAllocator</a> and release all its Chunks. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="5fb8edbf26f6ab26a0c332391909fa0c"></a><!-- doxytag: member="Loki::FixedAllocator::Initialize" ref="5fb8edbf26f6ab26a0c332391909fa0c" args="(std::size_t blockSize, std::size_t pageSize)" -->
void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#5fb8edbf26f6ab26a0c332391909fa0c">Initialize</a> (std::size_t blockSize, std::size_t pageSize)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initializes a <a class="el" href="a00056.html">FixedAllocator</a> by calculating # of blocks per <a class="el" href="a00025.html">Chunk</a>. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#c29973a11534fb1006fd28db97a17bed">Allocate</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#49ab7ca3364fe05f2d7d91248ee5d0e3">Deallocate</a> (void *p, <a class="el" href="a00025.html">Chunk</a> *hint)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="37df732230913b2dd9126a6b311586f0"></a><!-- doxytag: member="Loki::FixedAllocator::BlockSize" ref="37df732230913b2dd9126a6b311586f0" args="() const " -->
std::size_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#37df732230913b2dd9126a6b311586f0">BlockSize</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns block size with which the <a class="el" href="a00056.html">FixedAllocator</a> was initialized. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#4df95a9324de31f05d931f2eea25165e">TrimEmptyChunk</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#2b92d73c032c2ae6942ef9aadf6f27fc">TrimChunkList</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">std::size_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#e74cbab50e78bfa115d7c0fcdce00641">CountEmptyChunks</a> (void) const </td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#41a7ad189cba00f504635aade8b3d15c">IsCorrupt</a> (void) const </td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">const <a class="el" href="a00025.html">Chunk</a> *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00056.html#f84b504579cea189ce1c415ee8ed5d2c">HasBlock</a> (void *p) const </td></tr>

</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
Offers services for allocating fixed-sized objects. It has a container of "containers" of fixed-size blocks. The outer container has all the Chunks. The inner container is a <a class="el" href="a00025.html">Chunk</a> which owns some blocks.<p>
<dl class="user" compact><dt><b>Class Level Invariants</b></dt><dd><ul>
<li>There is always either zero or one <a class="el" href="a00025.html">Chunk</a> which is empty.</li><li>If this has no empty <a class="el" href="a00025.html">Chunk</a>, then emptyChunk_ is NULL.</li><li>If this has an empty <a class="el" href="a00025.html">Chunk</a>, then emptyChunk_ points to it.</li><li>If the <a class="el" href="a00025.html">Chunk</a> container is empty, then deallocChunk_ and allocChunk_ are NULL.</li><li>If the <a class="el" href="a00025.html">Chunk</a> container is not-empty, then deallocChunk_ and allocChunk_ are either NULL or point to Chunks within the container.</li><li>allocChunk_ will often point to the last <a class="el" href="a00025.html">Chunk</a> in the container since it was likely allocated most recently, and therefore likely to have an available block. </li></ul>
</dd></dl>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="c29973a11534fb1006fd28db97a17bed"></a><!-- doxytag: member="Loki::FixedAllocator::Allocate" ref="c29973a11534fb1006fd28db97a17bed" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * Loki::FixedAllocator::Allocate           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Returns pointer to allocated memory block of fixed size - or NULL if it failed to allocate. 
<p>References <a class="el" href="a00261.html#l00358">Loki::Chunk::Allocate()</a>, <a class="el" href="a00261.html#l00586">CountEmptyChunks()</a>, <a class="el" href="a00261.html#l00138">Loki::Chunk::HasAvailable()</a>, <a class="el" href="a00261.html#l00401">Loki::Chunk::IsCorrupt()</a>, and <a class="el" href="a00261.html#l00141">Loki::Chunk::IsFilled()</a>.</p>

<p>Referenced by <a class="el" href="a00261.html#l01109">Loki::SmallObjAllocator::Allocate()</a>.</p>

<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>

</div>
</div><p>
<a class="anchor" name="e74cbab50e78bfa115d7c0fcdce00641"></a><!-- doxytag: member="Loki::FixedAllocator::CountEmptyChunks" ref="e74cbab50e78bfa115d7c0fcdce00641" args="(void) const " -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t Loki::FixedAllocator::CountEmptyChunks           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td> const</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Returns count of empty Chunks held by this allocator. Complexity is O(C) where C is the total number of Chunks - empty or used. 
<p>References <a class="el" href="a00261.html#l00138">Loki::Chunk::HasAvailable()</a>.</p>

<p>Referenced by <a class="el" href="a00261.html#l00831">Allocate()</a>, <a class="el" href="a00261.html#l00888">Deallocate()</a>, <a class="el" href="a00261.html#l00607">IsCorrupt()</a>, and <a class="el" href="a00261.html#l00736">TrimEmptyChunk()</a>.</p>

<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>

</div>
</div><p>
<a class="anchor" name="49ab7ca3364fe05f2d7d91248ee5d0e3"></a><!-- doxytag: member="Loki::FixedAllocator::Deallocate" ref="49ab7ca3364fe05f2d7d91248ee5d0e3" args="(void *p, Chunk *hint)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Loki::FixedAllocator::Deallocate           </td>
          <td>(</td>
          <td class="paramtype">void *&nbsp;</td>
          <td class="paramname"> <em>p</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="a00025.html">Chunk</a> *&nbsp;</td>
          <td class="paramname"> <em>hint</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Deallocate a memory block previously allocated with Allocate. If the block is not owned by this <a class="el" href="a00056.html">FixedAllocator</a>, it returns false so that <a class="el" href="a00127.html">SmallObjAllocator</a> can call the default deallocator. If the block was found, this returns true. 
<p>References <a class="el" href="a00261.html#l00586">CountEmptyChunks()</a>, <a class="el" href="a00261.html#l00132">Loki::Chunk::HasBlock()</a>, <a class="el" href="a00261.html#l00502">Loki::Chunk::IsBlockAvailable()</a>, and <a class="el" href="a00261.html#l00401">Loki::Chunk::IsCorrupt()</a>.</p>

<p>Referenced by <a class="el" href="a00261.html#l01144">Loki::SmallObjAllocator::Deallocate()</a>.</p>

<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>

</div>
</div><p>
<a class="anchor" name="f84b504579cea189ce1c415ee8ed5d2c"></a><!-- doxytag: member="Loki::FixedAllocator::HasBlock" ref="f84b504579cea189ce1c415ee8ed5d2c" args="(void *p) const " -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">const <a class="el" href="a00025.html">Chunk</a> * Loki::FixedAllocator::HasBlock           </td>
          <td>(</td>
          <td class="paramtype">void *&nbsp;</td>
          <td class="paramname"> <em>p</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td> const</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Returns true if the block at address p is within a <a class="el" href="a00025.html">Chunk</a> owned by this <a class="el" href="a00056.html">FixedAllocator</a>. Complexity is O(C) where C is the total number of Chunks - empty or used. 
<p>References <a class="el" href="a00261.html#l00132">Loki::Chunk::HasBlock()</a>.</p>

<p>Referenced by <a class="el" href="a00261.html#l01168">Loki::SmallObjAllocator::Deallocate()</a>.</p>

<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>

</div>
</div><p>
<a class="anchor" name="41a7ad189cba00f504635aade8b3d15c"></a><!-- doxytag: member="Loki::FixedAllocator::IsCorrupt" ref="41a7ad189cba00f504635aade8b3d15c" args="(void) const " -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Loki::FixedAllocator::IsCorrupt           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td> const</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Determines if <a class="el" href="a00056.html">FixedAllocator</a> is corrupt. Checks data members to see if any have erroneous values, or violate class invariants. It also checks if any <a class="el" href="a00025.html">Chunk</a> is corrupt. Complexity is O(C) where C is the number of Chunks. If any data is corrupt, this will return true in release mode, or assert in debug mode. 
<p>References <a class="el" href="a00261.html#l00586">CountEmptyChunks()</a>, <a class="el" href="a00261.html#l00138">Loki::Chunk::HasAvailable()</a>, and <a class="el" href="a00261.html#l00401">Loki::Chunk::IsCorrupt()</a>.</p>

<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>

</div>
</div><p>
<a class="anchor" name="2b92d73c032c2ae6942ef9aadf6f27fc"></a><!-- doxytag: member="Loki::FixedAllocator::TrimChunkList" ref="2b92d73c032c2ae6942ef9aadf6f27fc" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Loki::FixedAllocator::TrimChunkList           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Releases unused spots from ChunkList. This takes constant time with respect to # of Chunks, but actual time depends on underlying memory allocator. <dl class="return" compact><dt><b>Returns:</b></dt><dd>False if no unused spots, true if some found and released. </dd></dl>

</div>
</div><p>
<a class="anchor" name="4df95a9324de31f05d931f2eea25165e"></a><!-- doxytag: member="Loki::FixedAllocator::TrimEmptyChunk" ref="4df95a9324de31f05d931f2eea25165e" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Loki::FixedAllocator::TrimEmptyChunk           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Releases the memory used by the empty <a class="el" href="a00025.html">Chunk</a>. This will take constant time under any situation. <dl class="return" compact><dt><b>Returns:</b></dt><dd>True if empty chunk found and released, false if none empty. </dd></dl>

<p>References <a class="el" href="a00261.html#l00149">Loki::Chunk::blocksAvailable_</a>, <a class="el" href="a00261.html#l00586">CountEmptyChunks()</a>, <a class="el" href="a00261.html#l00138">Loki::Chunk::HasAvailable()</a>, and <a class="el" href="a00261.html#l00346">Loki::Chunk::Release()</a>.</p>

<p>Referenced by <a class="el" href="a00261.html#l00558">~FixedAllocator()</a>.</p>

<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>

</div>
</div><p>
<hr>The documentation for this class was generated from the following file:<ul>
<li>SmallObj.cpp</ul>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 29 18:51:46 2009 for Loki by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>