aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/include_2nel_2misc_2heap__allocator_8h-source.html
blob: 03702703e1eb93a2b87aff6f250e39af7c7cf1bf (plain)
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
	<TITLE>nevrax.org : docs</TITLE>
	<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">

<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0>
 <TR>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>

<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 height=100%>
 <TR>
	<TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

		<!------ Begin Box ------>
		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0  cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
		<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td  colspan=2 bgcolor=#FFFFFF>
		<TABLE cellspacing=0 cellpadding=1 border=0>
			<tr><td ALIGN=middle><a  class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>heap_allocator.h</h1><a href="include_2nel_2misc_2heap__allocator_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025 
00026 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATOR_H</font>
00027 <font class="preprocessor"></font><font class="preprocessor">#define NL_HEAP_ALLOCATOR_H</font>
00028 <font class="preprocessor"></font>
00029 <font class="comment">/* </font>
00030 <font class="comment"> * Include "nel/misc/types_nl.h" but don't redefine new</font>
00031 <font class="comment"> */</font>
00032 <font class="preprocessor">#include "<a class="code" href="types__nl_8h.html">nel/misc/types_nl.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="mutex_8h.html">nel/misc/mutex.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="tds_8h.html">nel/misc/tds.h</a>"</font>
00035 
00036 <font class="preprocessor">#include &lt;vector&gt;</font>
00037 
00038 <font class="keyword">namespace </font>NLMISC 
00039 {
00040 
00042 
00043 <font class="comment">// Define this to disable debug features (use to trace buffer overflow and add debug informations in memory headers)</font>
00044 <font class="comment">// #define NL_HEAP_ALLOCATION_NDEBUG</font>
00045 
00046 <font class="comment">// Define this to activate internal checks (use to debug the heap code)</font>
00047 <font class="comment">// #define NL_HEAP_ALLOCATOR_INTERNAL_CHECKS</font>
00048 
00049 <font class="comment">// Define this to disable small block optimizations</font>
00050 <font class="comment">//#define NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00051 
00052 <font class="comment">// Stop when free a NULL pointer</font>
00053 <font class="comment">//#define NL_HEAP_STOP_NULL_FREE</font>
00054 
00055 <font class="comment">// Mutex to use with the allocator</font>
00056 <font class="keyword">typedef</font> <a class="code" href="mutex_8h.html#a2">CFastMutex</a> <a class="code" href="namespaceNLMISC.html#a168">CAllocatorMutex</a>;                     <font class="comment">// Not fair, non-system, using sleep(), but very fast</font>
00057 <font class="comment">//typedef CFairMutex CAllocatorMutex;           // Fair, fastest system mutex under Windows</font>
00058 <font class="comment">//typedef CUnfairMutex CAllocatorMutex;         // Unfair, slowest system mutex under Windows</font>
00059 
00061 
00062 <font class="comment">/*</font>
00063 <font class="comment"> * A heap allocator with a lot of functionnality.</font>
00064 <font class="comment"> * Used by the NeL memory manager as default allocator.</font>
00065 <font class="comment">**/</font>
<a name="l00066"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html">00066</a> <font class="keyword">class </font>CHeapAllocator
00067 {
00068 <font class="keyword">public</font>:
00069 
00070         <font class="keyword">enum</font> 
00071         { 
00072                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a>               =       8,
00073                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s2">CategoryStringLength</a>    =       8,
00074                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s3">BeginNodeMarkers</a>                =       <font class="charliteral">'&lt;'</font>,
00075                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s4">EndNodeMarkers</a>                  =       <font class="charliteral">'&gt;'</font>,
00076                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s5">UnallocatedMemory</a>               =       0xba,
00077                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s6">UninitializedMemory</a>             =       0xbc,
00078                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s7">DeletedMemory</a>                   =       0xbd,
00079                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s8">NameLength</a>                              =       32
00080         };
00081 
<a name="l00085"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19">00085</a>         <font class="keyword">enum</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19">TBlockAllocationMode</a> 
00086         { 
00088                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19s9">Grow</a>, 
00089 
00091                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19s10">DontGrow</a> 
00092         };
00093         
<a name="l00097"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20">00097</a>         <font class="keyword">enum</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20">TOutOfMemoryMode</a> 
00098         { 
00100                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20s11">ThrowException</a>, 
00101 
00103                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20s12">ReturnNull</a> 
00104         };
00105         
<a name="l00106"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#s0">00106</a>         <font class="keyword">typedef</font> <font class="keywordtype">char</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s0">TCategoryString</a>[<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s2">CategoryStringLength</a>];
00107 
00108 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00109 <font class="preprocessor"></font>
<a name="l00110"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html">00110</a>         <font class="keyword">struct </font>CMemoryLeakBlock
00111         {
00112         <font class="keyword">public</font>:
<a name="l00113"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m0">00113</a>                 <font class="keywordtype">void</font>                    *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m0">Adress</a>;
<a name="l00114"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m1">00114</a>                 uint                    <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m1">BlockSize</a>;
<a name="l00115"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m2">00115</a>                 <font class="keyword">const</font> <font class="keywordtype">char</font>              *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m2">SourceFile</a>;
<a name="l00116"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m3">00116</a>                 uint                    <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m3">Line</a>;
<a name="l00117"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m4">00117</a>                 TCategoryString <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMemoryLeakBlock.html#m4">Category</a>;
00118         };
00119 
00120 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00121 <font class="preprocessor"></font>
00122         <font class="comment">// Constructor / Destructor</font>
00123         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a0">CHeapAllocator</a> (        uint mainBlockSize=1024*1024*10, 
00124                         uint blockCount=1, 
00125                         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19">TBlockAllocationMode</a> blockAllocationMode = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19s9">Grow</a>, 
00126                         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20">TOutOfMemoryMode</a> outOfMemoryMode = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20s11">ThrowException</a> );
00127         <font class="keyword">virtual</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a1">~CHeapAllocator</a> ();
00128 
00129         <font class="comment">// Allocation / desallocation</font>
00130 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00131 <font class="preprocessor"></font>        <font class="comment">/* Use the NelAlloc macro */</font>
00132         <font class="keywordtype">void</font>                                    *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#a2">allocate</a> (uint size, <font class="keyword">const</font> <font class="keywordtype">char</font> *sourceFile, uint line, <font class="keyword">const</font> <font class="keywordtype">char</font> *category);
00133         <font class="comment">/* Use the NelRealloc macro */</font>
00134         <font class="keywordtype">void</font>                                    *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#a3">reallocate</a> (<font class="keywordtype">void</font> *ptr, uint size, <font class="keyword">const</font> <font class="keywordtype">char</font> *sourceFile, uint line, <font class="keyword">const</font> <font class="keywordtype">char</font> *category);
00135 <font class="preprocessor">#else   // NL_HEAP_ALLOCATION_NDEBUG</font>
00136 <font class="preprocessor"></font>        <font class="keywordtype">void</font>                                    *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#a2">allocate</a> (uint size);
00137         <font class="keywordtype">void</font>                                    *realloc (<font class="keywordtype">void</font> *ptr, uint size);
00138 <font class="preprocessor">#endif  // NL_HEAP_ALLOCATION_NDEBUG</font>
00139 <font class="preprocessor"></font>        <font class="keywordtype">void</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a> (<font class="keywordtype">void</font> *ptr);
00140         <font class="keywordtype">void</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a5">freeAll</a> ();
00141         <font class="keywordtype">void</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a6">releaseMemory</a> ();
00142 
00143         <font class="comment">// Return an allocated block size</font>
00144         <font class="keyword">static</font> uint                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#d0">getBlockSize</a> (<font class="keywordtype">void</font> *block);
00145 
00146         <font class="comment">// Performance control</font>
00147 
00148         <font class="comment">// Returns false if the block size choosed i too big (&gt;= 1 Go)</font>
00149         <font class="keywordtype">bool</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a7">setMainBlockSize</a> (uint mainBlockSize);
00150         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a8">getMainBlockSize</a> () <font class="keyword">const</font>;
00151         <font class="keywordtype">bool</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a9">setMainBlockCount</a> (uint blockCount);
00152         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a10">getMainBlockCount</a> () <font class="keyword">const</font>;
00153         <font class="keywordtype">void</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a11">setBlockAllocationMode</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19">TBlockAllocationMode</a> mode);
00154         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19">TBlockAllocationMode</a>    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a12">getBlockAllocationMode</a> () <font class="keyword">const</font>;
00155         <font class="keywordtype">void</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a13">setOutOfMemoryMode</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20">TOutOfMemoryMode</a> mode);
00156         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20">TOutOfMemoryMode</a>                <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a14">getOutOfMemoryMode</a> () <font class="keyword">const</font>;
00157 
00158         <font class="comment">// Heap control</font>
00159         <font class="keywordtype">bool</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a15">checkHeap</a> (<font class="keywordtype">bool</font> stopOnError) <font class="keyword">const</font>;
00160 
00161         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a16">getAllocatedMemory</a> () <font class="keyword">const</font>;
00162 
00163         <font class="comment">/* Return the amount of free memoyr available in the allocator */</font>
00164         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a17">getFreeMemory</a> () <font class="keyword">const</font>;
00165 
00166         <font class="comment">/* Return the total amount of memory allocated by the allocator */</font>
00167         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a18">getTotalMemoryUsed</a> () <font class="keyword">const</font>;
00168 
00169         <font class="comment">/* Return the amount of memory used by the small block optimisation */</font>
00170         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a19">getSmallBlockMemory</a> () <font class="keyword">const</font>;
00171 
00172         <font class="comment">/* Return the amount of allocated system memory */</font>
00173         <font class="keyword">static</font> uint                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#d1">getAllocatedSystemMemory</a> ();
00174 
00175         <font class="comment">/* Return the amount of allocated system memory used by the allocator */</font>
00176         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a20">getAllocatedSystemMemoryByAllocator</a> ();
00177 
00178         <font class="keywordtype">float</font>                                   <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a21">getFragmentationRatio</a> () <font class="keyword">const</font>;
00179         <font class="keywordtype">void</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a22">setName</a> (<font class="keyword">const</font> <font class="keywordtype">char</font>* name);
00180         <font class="keyword">const</font> <font class="keywordtype">char</font>                              *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#a23">getName</a> () <font class="keyword">const</font>;
00181 
00182 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00183 <font class="preprocessor"></font><font class="comment">/*      void                                    debugAddBreakpoint (uint32 allocateNumber);</font>
00184 <font class="comment">        void                                    debugRemoveBreakpoints ();*/</font>
00185         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a24">debugGetDebugInfoSize</a> () <font class="keyword">const</font>;
00186         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a25">debugGetSBDebugInfoSize</a> () <font class="keyword">const</font>;
00187         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a26">debugGetLBDebugInfoSize</a> () <font class="keyword">const</font>;
00188         uint                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a27">debugGetAllocatedMemoryByCategory</a> (<font class="keyword">const</font> <font class="keywordtype">char</font>* category) <font class="keyword">const</font>;
00189         <font class="keywordtype">bool</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a28">debugStatisticsReport</a> (<font class="keyword">const</font> <font class="keywordtype">char</font>* stateFile, <font class="keywordtype">bool</font> memoryMap);
00190         <font class="keywordtype">void</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a29">debugAlwaysCheckMemory</a> (<font class="keywordtype">bool</font> alwaysCheck);
00191         <font class="keywordtype">bool</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a30">debugIsAlwaysCheckMemory</a> (<font class="keywordtype">bool</font> alwaysCheck) <font class="keyword">const</font>;
00192 
00193         <font class="comment">// Heap debug</font>
00194         <font class="keywordtype">void</font>                                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a31">debugReportMemoryLeak</a> ();
00195 
00196 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00197 <font class="preprocessor"></font>
00198         <font class="comment">// Overridable</font>
00199         <font class="keyword">virtual</font> uint8                   *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#a32">allocateBlock</a> (uint size);
00200         <font class="keyword">virtual</font> <font class="keywordtype">void</font>                    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a33">freeBlock</a> (uint8 *block);
00201 
00202 <font class="keyword">private</font>:
00203 
00204         <font class="comment">// Constants for freeNode block size</font>
00205         <font class="keyword">enum</font> 
00206         { 
00207                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u6u0">FreeNodeBlockSize</a> = 128, 
00208                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u6u1">FreeNodeBlockSizeShift</a> = 7, 
00209                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u6u2">FreeNodeBlockSizeMask</a> = 0x7f 
00210         };
00211 
00212         <font class="comment">// Minimal size and align</font>
00213         <font class="keyword">enum</font> 
00214         { 
00215                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u7u3">Align</a> = 8,
00216                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u7u4">BlockDataSizeMin</a> = 1&lt;&lt;4
00217         };
00218 
00219         <font class="keyword">struct </font>CNodeBegin;
00220 
00221 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00222 <font class="preprocessor"></font>        <font class="keyword">struct </font>CNodeEnd;
00223 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00224 <font class="preprocessor"></font>
00225         <font class="keyword">struct </font>CFreeNode;
00226 
<a name="l00227"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html">00227</a>         <font class="keyword">struct </font>CNodeBegin
00228         {
00229                 <font class="keyword">enum</font>    
00230                 { 
00231                         <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#s4s0">MarkerSize</a>=6
00232                 };
00233 
00234                 <font class="comment">// Flags for the memory node</font>
00235                 <font class="keyword">enum</font>    
00236                 { 
00237                         <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#s5s1">Free</a>=0x40000000,
00238                         <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#s5s2">Last</a>=0x80000000,
00239                         <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#s5s3">SizeMask</a>=0x3fffffff,
00240                 };
00241 
00242 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l00243"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m0">00243</a> <font class="preprocessor"></font>                <font class="keywordtype">char</font>            <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m0">BeginMarkers</a>[<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#s4s0">MarkerSize</a>];                       <font class="comment">// &lt;&lt;&lt;&lt;&lt;&lt;&lt;</font>
<a name="l00244"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m1">00244</a>                 uint16          <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m1">Line</a>;                                                           <font class="comment">// Source line number</font>
<a name="l00245"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m2">00245</a>                 <font class="keywordtype">char</font>            <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m2">Category</a>[CategoryStringLength];         <font class="comment">// Category name</font>
<a name="l00246"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m3">00246</a>                 <font class="keyword">const</font> <font class="keywordtype">char</font>      *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m3">File</a>;                                                          <font class="comment">// Source file name pointer</font>
<a name="l00247"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m4">00247</a>                 CHeapAllocator          *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m4">Heap</a>;                                          <font class="comment">// Heap holder of this node</font>
<a name="l00248"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m5">00248</a>                 uint32          *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m5">EndMagicNumber</a>;                                        <font class="comment">// Pointer on the end magic number</font>
<a name="l00249"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m6">00249</a>                 uint32          <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m6">AllocateNumber</a>;                                         <font class="comment">// Align structure to 80 bytes</font>
00250 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00251 <font class="preprocessor"></font>
<a name="l00252"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m7">00252</a>                 uint32          <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m7">SizeAndFlags</a>;                                           <font class="comment">// Size of the user memory zone of 30 bits (1 Go max), and 2 flags (Free/Used and LastBlock)</font>
<a name="l00253"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m8">00253</a>                 CNodeBegin      *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeBegin.html#m8">Previous</a>;                                                      <font class="comment">// Previous node in large block mode / Small block pointer in small block mode</font>
00254         };
00255 
00256 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l00257"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeEnd.html">00257</a> <font class="preprocessor"></font>        <font class="keyword">struct </font>CNodeEnd
00258         {
00259                 <font class="keyword">enum</font>    
00260                 { 
00261                         <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeEnd.html#s1s0">MarkerSize</a>=4
00262                 };
00263 
<a name="l00264"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeEnd.html#m0">00264</a>                 uint32          <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeEnd.html#m0">MagicNumber</a>;                                            <font class="comment">// CRC32 of the node pointer and the node header. Can be move backward to fit the data</font>
<a name="l00265"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeEnd.html#m1">00265</a>                 <font class="keywordtype">char</font>            <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeEnd.html#m1">EndMarkers</a>[<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNodeEnd.html#s1s0">MarkerSize</a>];                         <font class="comment">// &gt;&gt;&gt;&gt;</font>
00266         };
00267 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00268 <font class="preprocessor"></font>
00269 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATION_NDEBUG</font>
00270 <font class="preprocessor"></font>
00271 <font class="preprocessor">#define NL_HEAP_NODE_END_SIZE 0</font>
00272 <font class="preprocessor"></font>
00273 <font class="preprocessor">#else // NL_HEAP_ALLOCATION_NDEBUG</font>
00274 <font class="preprocessor"></font>
<a name="l00275"></a><a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a0">00275</a> <font class="preprocessor">#define NL_HEAP_NODE_END_SIZE sizeof(CNodeEnd)</font>
00276 <font class="preprocessor"></font>
00277 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00278 <font class="preprocessor"></font>
00279 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00280 <font class="preprocessor"></font>        <font class="keyword">static</font> uint32                   <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (<font class="keyword">const</font> CNodeBegin *node);
00281 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00282 <font class="preprocessor"></font>        <font class="keyword">static</font> <font class="keyword">const</font> CNodeBegin *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a>    (<font class="keyword">const</font> CNodeBegin *current);
00283         <font class="keyword">static</font> CNodeBegin               *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a>    (CNodeBegin *current);
00284         <font class="keyword">static</font> <font class="keyword">const</font> CFreeNode  *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f3">getFreeNode</a>    (<font class="keyword">const</font> CNodeBegin *current);
00285         <font class="keyword">static</font> CFreeNode                *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f3">getFreeNode</a>    (CNodeBegin *current);
00286         <font class="keyword">static</font> <font class="keyword">const</font> CNodeBegin *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f5">getNode</a>                (<font class="keyword">const</font> CFreeNode *current);
00287         <font class="keyword">static</font> CNodeBegin               *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f5">getNode</a>                (CFreeNode *current);
00288         <font class="keyword">static</font> uint                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a>             (<font class="keyword">const</font> CNodeBegin *current);
00289         <font class="keyword">static</font> <font class="keywordtype">bool</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a>              (<font class="keyword">const</font> CNodeBegin *current);
00290         <font class="keyword">static</font> <font class="keywordtype">bool</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a>              (<font class="keyword">const</font> CNodeBegin *current);
00291         <font class="keyword">static</font> <font class="keywordtype">bool</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f10">isNodeLast</a>              (<font class="keyword">const</font> CNodeBegin *current);
00292         <font class="keyword">static</font> <font class="keywordtype">bool</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f11">isNodeSmall</a>             (<font class="keyword">const</font> CNodeBegin *current);
00293         <font class="keyword">static</font> <font class="keywordtype">bool</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a>               (<font class="keyword">const</font> CFreeNode *current);
00294         <font class="keyword">static</font> <font class="keywordtype">bool</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f13">isNodeBlack</a>             (<font class="keyword">const</font> CFreeNode *current);
00295         <font class="keyword">static</font> <font class="keywordtype">void</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f14">setNodeFree</a>             (CNodeBegin *current);
00296         <font class="keyword">static</font> <font class="keywordtype">void</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f15">setNodeUsed</a>             (CNodeBegin *current);
00297         <font class="keyword">static</font> <font class="keywordtype">void</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f16">setNodeLast</a>             (CNodeBegin *current, <font class="keywordtype">bool</font> last);
00298         <font class="keyword">static</font> <font class="keywordtype">void</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f17">setNodeSize</a>             (CNodeBegin *current, uint size);
00299         <font class="keyword">static</font> <font class="keywordtype">void</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f18">setNodeColor</a>    (CFreeNode *current, <font class="keywordtype">bool</font> red);
00300         <font class="keyword">static</font> <font class="keywordtype">void</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a>              (CFreeNode *current);
00301         <font class="keyword">static</font> <font class="keywordtype">void</font>                             <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a>    (CFreeNode *current);
00302 
<a name="l00303"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMainBlock.html">00303</a>         <font class="keyword">struct </font>CMainBlock
00304         {
<a name="l00305"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMainBlock.html#m0">00305</a>                 uint            <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMainBlock.html#m0">Size</a>;
<a name="l00306"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMainBlock.html#m1">00306</a>                 uint8           *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMainBlock.html#m1">Ptr</a>;
<a name="l00307"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMainBlock.html#m2">00307</a>                 CMainBlock      *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMainBlock.html#m2">Next</a>;
00308         };
00309         
00310         <font class="keyword">static</font> <font class="keyword">const</font> CNodeBegin *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a>   (<font class="keyword">const</font> CMainBlock *mainBlock);
00311         <font class="keyword">static</font> CNodeBegin               *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a>   (CMainBlock *mainBlock);
00312 
00313         <font class="comment">/* Integrity check of a single node. Called at each allocation / deallocation when NL_HEAP_ALLOCATION_NDEBUG is not defined.</font>
00314 <font class="comment">           Call it inside a critical section. */</font>
00315         <font class="keywordtype">bool</font>            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c0">checkNodeLB</a> (<font class="keyword">const</font> CMainBlock *mainBlock, <font class="keyword">const</font> CNodeBegin *previous, 
00316                                                         <font class="keyword">const</font> CNodeBegin *current, <font class="keyword">const</font> CNodeBegin *next, <font class="keywordtype">bool</font> stopOnError) <font class="keyword">const</font>;
00317 
<a name="l00318"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html">00318</a>         <font class="keyword">struct </font>CFreeNode
00319         {
00320                 <font class="keyword">enum</font>
00321                 {
00322                         <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#s1s0">Red</a> = 1
00323                 };
<a name="l00324"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m0">00324</a>                 CFreeNode       *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m0">Left</a>;
<a name="l00325"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m1">00325</a>                 CFreeNode       *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m1">Right</a>;
<a name="l00326"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m2">00326</a>                 CFreeNode       *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m2">Parent</a>;
<a name="l00327"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m3">00327</a>                 uint32          <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m3">Flags</a>;
00328         };
00329 
00330         <font class="keyword">enum</font>
00331         {
00332                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u8u5">UserDataBlockSizeMin</a> = <font class="keyword">sizeof</font>(CFreeNode)
00333         };
00334 
00335         <font class="comment">// Manage freeNode</font>
00336         <font class="keyword">inline</font> <font class="keywordtype">void</font>                     <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c1">rotateLeft</a> (CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00337         <font class="keyword">inline</font> <font class="keywordtype">void</font>                     <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c2">rotateRight</a> (CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00338         <font class="keyword">inline</font> <font class="keywordtype">void</font>                     <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c3">insert</a> (CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00339         <font class="keyword">inline</font> <font class="keywordtype">void</font>                     <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c4">erase</a> (CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>);
00340         <font class="keyword">inline</font> CFreeNode        *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#c5">find</a> (uint size);
00341 
00342         <font class="comment">// Manage blocks</font>
00343         <font class="keyword">inline</font> <font class="keyword">static</font> <font class="keywordtype">void</font>                      <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f23">mergeNode</a> (CNodeBegin *node);
00344         <font class="keyword">inline</font> CNodeBegin                       *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#c6">splitNode</a> (CNodeBegin *node, uint newSize);
00345         <font class="keyword">inline</font> <font class="keywordtype">void</font>                                     <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c7">initEmptyBlock</a> (CMainBlock&amp; mainBlock);
00346 
00347 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00348 <font class="preprocessor"></font>        <font class="keyword">inline</font> <font class="keyword">static</font> <font class="keywordtype">void</font>                      <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f24">computeCRC32</a> (uint32 &amp;crc, <font class="keyword">const</font> <font class="keywordtype">void</font>* buffer, <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> count);
00349 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00350 <font class="preprocessor"></font>
00351         <font class="comment">// Checks</font>
00352         <font class="keywordtype">bool</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c8">checkFreeNode</a> (<font class="keyword">const</font> CFreeNode *current, <font class="keywordtype">bool</font> stopOnError, <font class="keywordtype">bool</font> recurse) <font class="keyword">const</font>;
00353 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00354 <font class="preprocessor"></font>        <font class="keywordtype">void</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">checkNode</a> (<font class="keyword">const</font> CNodeBegin *current, uint32 crc) <font class="keyword">const</font>;
00355 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00356 <font class="preprocessor"></font>
00357         <font class="comment">// Performe full integrity check of the heap, free list and smallblock. Call it outside critical sections.</font>
00358         <font class="keywordtype">bool</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c10">internalCheckHeap</a> (<font class="keywordtype">bool</font> stopOnError) <font class="keyword">const</font>;
00359 
00360         <font class="comment">// Synchronisation</font>
00361         <font class="keywordtype">void</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> () <font class="keyword">const</font>;
00362         <font class="keywordtype">void</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> () <font class="keyword">const</font>;
00363         <font class="keywordtype">void</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c13">enterCriticalSectionSB</a> () <font class="keyword">const</font>;
00364         <font class="keywordtype">void</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c14">leaveCriticalSectionSB</a> () <font class="keyword">const</font>;
00365         <font class="keywordtype">void</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c15">enterCriticalSectionLB</a> () <font class="keyword">const</font>;
00366         <font class="keywordtype">void</font>                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c16">leaveCriticalSectionLB</a> () <font class="keyword">const</font>;
00367 
00368         <font class="comment">// The Null node</font>
<a name="l00369"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html">00369</a>         <font class="keyword">struct </font>CNullNode
00370         {
<a name="l00371"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m0">00371</a>                 uint8                   <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m0">NodeBeginBuffer</a>[<font class="keyword">sizeof</font>(CNodeBegin)];
<a name="l00372"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">00372</a>                 CFreeNode               <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
00373         };
00374 
<a name="l00375"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o0">00375</a>         uint                                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o0">_MainBlockSize</a>;
<a name="l00376"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o1">00376</a>         uint                                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o1">_BlockCount</a>;
<a name="l00377"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o2">00377</a>         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s19">TBlockAllocationMode</a>            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o2">_BlockAllocationMode</a>;
<a name="l00378"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o3">00378</a>         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s20">TOutOfMemoryMode</a>                        <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o3">_OutOfMemoryMode</a>;
00379 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l00380"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o4">00380</a> <font class="preprocessor"></font>        <font class="keywordtype">bool</font>                                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o4">_AlwaysCheck</a>;
00381 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00382 <font class="preprocessor"></font>
00383         <font class="comment">// List of main block.</font>
<a name="l00384"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">00384</a>         CMainBlock                                      *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
00385 
00386         <font class="comment">// Members</font>
<a name="l00387"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">00387</a>         CFreeNode                                       *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>;
<a name="l00388"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">00388</a>         CNullNode                                       <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>;
<a name="l00389"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o8">00389</a>         <font class="keyword">mutable</font> <a class="code" href="namespaceNLMISC.html#a168">CAllocatorMutex</a>         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o8">_MutexLB</a>;
00390 
<a name="l00391"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o9">00391</a>         <font class="keywordtype">char</font>                                            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o9">_Name</a>[<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s8">NameLength</a>];
00392 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l00393"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o10">00393</a> <font class="preprocessor"></font>        uint32                                          <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o10">_AllocateCount</a>;
00394         <font class="comment">// std::set&lt;uint32&gt;                     _Breakpoints;</font>
00395 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00396 <font class="preprocessor"></font>
00397         <font class="comment">// *********************************************************</font>
00398 
00400 
00401 <font class="keyword">public</font>:
00402         <font class="comment">// Small block size</font>
00403         <font class="keyword">enum</font>
00404         {
00405                 <font class="comment">// Small block granularity</font>
00406                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s13">SmallBlockGranularityShift</a> = 3,
00407 
00408                 <font class="comment">// Small block granularity</font>
00409                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s14">SmallBlockGranularity</a> = 1&lt;&lt;<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s13">SmallBlockGranularityShift</a>,
00410 
00411                 <font class="comment">// Smallest block size</font>
00412                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s15">FirstSmallBlock</a> = 8,
00413 
00414                 <font class="comment">// Largest block size</font>
00415                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s16">LastSmallBlock</a> = 128,
00416 
00417                 <font class="comment">// Size of a smallblock pool</font>
00418                 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a> = 20
00419         };
00420 
<a name="l00421"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CSmallBlockPool.html">00421</a>         <font class="keyword">struct </font>CSmallBlockPool
00422         {
00423         <font class="keyword">public</font>:
<a name="l00424"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CSmallBlockPool.html#m0">00424</a>                 uint32                          <a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CSmallBlockPool.html#m0">Size</a>;
<a name="l00425"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CSmallBlockPool.html#m1">00425</a>                 CSmallBlockPool         *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CSmallBlockPool.html#m1">Next</a>;
00426         };
00427 
00428 <font class="keyword">private</font>:
00429 
00430         <font class="comment">// Some internal methods</font>
00431 
00432         <font class="comment">/* Integrity check of a single node. Called at each allocation / deallocation when NL_HEAP_ALLOCATION_NDEBUG is not defined.</font>
00433 <font class="comment">           Call it inside a critical section. */</font>
00434         <font class="keywordtype">bool</font>            <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c17">checkNodeSB</a> (<font class="keyword">const</font> CSmallBlockPool *mainBlock, <font class="keyword">const</font> CNodeBegin *previous, <font class="keyword">const</font> CNodeBegin *current, 
00435                 <font class="keyword">const</font> CNodeBegin *next, <font class="keywordtype">bool</font> stopOnError) <font class="keyword">const</font>;
00436 
00437         <font class="comment">// Get a block from a small block</font>
00438         <font class="keyword">static</font> CNodeBegin       *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (CSmallBlockPool *smallBlock, uint blockIndex);
00439 
00440         <font class="comment">// Get next free small block</font>
00441         <font class="keyword">static</font> CNodeBegin       *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f26">getNextSmallBlock</a> (CNodeBegin *previous);
00442 
00443         <font class="comment">// Set next free small block</font>
00444         <font class="keyword">static</font> <font class="keywordtype">void</font>                     <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f27">setNextSmallBlock</a> (CNodeBegin *previous, CNodeBegin *next);
00445 
00446         <font class="comment">// Some macros</font>
<a name="l00447"></a><a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a1">00447</a> <font class="preprocessor">#define NL_SMALLBLOCK_COUNT (1+(LastSmallBlock - FirstSmallBlock)/SmallBlockGranularity)</font>
<a name="l00448"></a><a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a2">00448</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_SIZE_TO_SMALLBLOCK_INDEX(size) ((size-1)&gt;&gt;SmallBlockGranularityShift)</font>
<a name="l00449"></a><a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a3">00449</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_ALIGN_SIZE_FOR_SMALLBLOCK(size) (((size) + SmallBlockGranularity-1) &amp; ~(SmallBlockGranularity-1))</font>
00450 <font class="preprocessor"></font>
00451         <font class="comment">// The free smallblock array by size</font>
<a name="l00452"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o11">00452</a>         <font class="keyword">volatile</font> CNodeBegin                     *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o11">_FreeSmallBlocks</a>[<a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a1">NL_SMALLBLOCK_COUNT</a>];
<a name="l00453"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">00453</a>         <font class="keyword">volatile</font> CSmallBlockPool        *<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
00454 
<a name="l00455"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o13">00455</a>         <font class="keyword">mutable</font> <a class="code" href="namespaceNLMISC.html#a168">CAllocatorMutex</a>         <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o13">_MutexSB</a>;
00456 
00457         <font class="comment">// *********************************************************</font>
00458 
00460 <font class="keyword">public</font>:
00461 
00462         <font class="comment">/* Push the category string. Add the string at the top of the category string stack. The string str must be a static pointer.</font>
00463 <font class="comment">         * There is one stack per thread. */</font>
00464         <font class="keywordtype">void</font>    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a34">debugPushCategoryString</a> (<font class="keyword">const</font> <font class="keywordtype">char</font> *str);
00465 
00466         <font class="comment">// Remove the last pushed category string from the category stack</font>
00467         <font class="keywordtype">void</font>    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a35">debugPopCategoryString</a> ();
00468 
00469 <font class="keyword">private</font>:
00470 
00471         <font class="comment">/* Struct for the category stack */</font>
<a name="l00472"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CCategory.html">00472</a>         <font class="keyword">struct </font>CCategory
00473         {
<a name="l00474"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CCategory.html#m0">00474</a>                 <font class="keyword">const</font> <font class="keywordtype">char</font>      *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CCategory.html#m0">Name</a>;
<a name="l00475"></a><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CCategory.html#m1">00475</a>                 CCategory       *<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CCategory.html#m1">Next</a>;
00476         };
00477 
00478         <font class="comment">/* Thread dependant storage of category stack */</font>
<a name="l00479"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#o14">00479</a>         CTDS    <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o14">_CategoryStack</a>;
00480 };
00481 
00483 
00484 <font class="comment">/* Heap macro */</font>
00485 <font class="preprocessor">#ifdef  NL_HEAP_ALLOCATION_NDEBUG</font>
00486 <font class="preprocessor"></font>
00487 <font class="comment">/* NelAlloc: category can be NULL. Then, category string will be the last pushed category string. */</font>
00488 <font class="preprocessor">#define NelAlloc(heap,size,category) ((heap).allocate (size))</font>
00489 <font class="preprocessor"></font>
00490 <font class="comment">/* NelRealloc: category can be NULL. Then, category string will be the last pushed category string. */</font>
00491 <font class="preprocessor">#define NelRealloc(heap,size,ptr,category) (heap.allocate (ptr, size))</font>
00492 <font class="preprocessor"></font>
00493 <font class="preprocessor">#else // NL_HEAP_ALLOCATION_NDEBUG</font>
00494 <font class="preprocessor"></font>
00495 <font class="comment">/* NelAlloc: category can be NULL. Then, category string will be the last pushed category string. */</font>
<a name="l00496"></a><a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a4">00496</a> <font class="preprocessor">#define NelAlloc(heap,size,category) ((heap).allocate (size, __FILE__, __LINE__, category))</font>
00497 <font class="preprocessor"></font>
00498 <font class="comment">/* NelRealloc: category can be NULL. Then, category string will be the last pushed category string. */</font>
<a name="l00499"></a><a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a5">00499</a> <font class="preprocessor">#define NelRealloc(heap,size,ptr,category) (heap.allocate (ptr, size, __FILE__, __LINE__, category))</font>
00500 <font class="preprocessor"></font>
00501 <font class="preprocessor">#endif  //NL_HEAP_ALLOCATION_NDEBUG</font>
00502 <font class="preprocessor"></font>
00503 } <font class="comment">// NLMISC </font>
00504 
00505 <font class="preprocessor">#endif // NL_HEAP_ALLOCATOR_H</font>
</pre></div>

<!-- footer -->
<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>