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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
|
<!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> <A CLASS=uplinks HREF=><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A> </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>
<!-- 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> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>heap_allocator_inline.h</h1><a href="include_2nel_2misc_2heap__allocator__inline_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_INLINE_H</font>
00027 <font class="preprocessor"></font><font class="preprocessor">#define NL_HEAP_ALLOCATOR_INLINE_H</font>
00028 <font class="preprocessor"></font>
00029 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATOR_INTERNAL_CHECKS</font>
00030 <font class="preprocessor"></font><font class="preprocessor">#define internalAssert(a) memory_assert(a)</font>
00031 <font class="preprocessor"></font><font class="preprocessor">#else // NL_HEAP_ALLOCATOR_INTERNAL_CHECKS</font>
<a name="l00032"></a><a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">00032</a> <font class="preprocessor"></font><font class="preprocessor">#define internalAssert(a) ((void)0)</font>
00033 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_HEAP_ALLOCATOR_INTERNAL_CHECKS</font>
00034 <font class="preprocessor"></font>
00035 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATION_NDEBUG</font>
00036 <font class="preprocessor"></font>
00037 <font class="preprocessor">#define NL_UPDATE_MAGIC_NUMBER(node) ((void)0)</font>
00038 <font class="preprocessor"></font><font class="preprocessor">#define NL_UPDATE_MAGIC_NUMBER_FREE_NODE(node) ((void)0)</font>
00039 <font class="preprocessor"></font>
00040 <font class="preprocessor">#else // NL_HEAP_ALLOCATION_NDEBUG</font>
00041 <font class="preprocessor"></font>
<a name="l00042"></a><a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">00042</a> <font class="preprocessor">#define NL_UPDATE_MAGIC_NUMBER(node) {\</font>
00043 <font class="preprocessor"> uint32 crc = evalMagicNumber (node);\</font>
00044 <font class="preprocessor"> *(node->EndMagicNumber) = crc;\</font>
00045 <font class="preprocessor"> }</font>
00046 <font class="preprocessor"></font>
<a name="l00047"></a><a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">00047</a> <font class="preprocessor">#define NL_UPDATE_MAGIC_NUMBER_FREE_NODE(node) {\</font>
00048 <font class="preprocessor"> if (node != &_NullNode.FreeNode) \</font>
00049 <font class="preprocessor"> { \</font>
00050 <font class="preprocessor"> uint32 crc = evalMagicNumber (getNode (node));\</font>
00051 <font class="preprocessor"> *(getNode (node)->EndMagicNumber) = crc;\</font>
00052 <font class="preprocessor"> } \</font>
00053 <font class="preprocessor"> }</font>
00054 <font class="preprocessor"></font>
00055 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00056 <font class="preprocessor"></font>
00057 <font class="preprocessor">#if defined (NL_OS_WINDOWS)</font>
00058 <font class="preprocessor"></font><font class="preprocessor">#define NL_ALLOC_STOP _asm { int 3 }</font>
00059 <font class="preprocessor"></font><font class="preprocessor">#else</font>
<a name="l00060"></a><a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">00060</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_ALLOC_STOP abort()</font>
00061 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00062 <font class="preprocessor"></font>
00063 <font class="comment">// *********************************************************</font>
00064 <font class="comment">// Set / Get methods</font>
00065 <font class="comment">// *********************************************************</font>
00066
00067 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::isNodeFree (<font class="keyword">const</font> CNodeBegin *node)
00068 {
00069 <font class="keywordflow">return</font> (node->SizeAndFlags & CNodeBegin::Free) != 0;
00070 }
00071
00072 <font class="comment">// *********************************************************</font>
00073
00074 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::isNodeUsed (<font class="keyword">const</font> CNodeBegin *node)
00075 {
00076 <font class="keywordflow">return</font> (node->SizeAndFlags & CNodeBegin::Free) == 0;
00077 }
00078
00079 <font class="comment">// *********************************************************</font>
00080
00081 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::isNodeLast (<font class="keyword">const</font> CNodeBegin *node)
00082 {
00083 <font class="keywordflow">return</font> (node->SizeAndFlags & CNodeBegin::Last) != 0;
00084 }
00085
00086 <font class="comment">// *********************************************************</font>
00087
00088 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::isNodeSmall (<font class="keyword">const</font> CNodeBegin *node)
00089 {
00090 <font class="preprocessor">#ifdef NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00091 <font class="preprocessor"></font> <font class="keywordflow">return</font> <font class="keyword">false</font>;
00092 <font class="preprocessor">#else // NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00093 <font class="preprocessor"></font> <font class="keywordflow">return</font> getNodeSize (node) <= LastSmallBlock;
00094 <font class="preprocessor">#endif // NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00095 <font class="preprocessor"></font>}
00096
00097 <font class="comment">// *********************************************************</font>
00098
00099 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::isNodeRed (<font class="keyword">const</font> CFreeNode *node)
00100 {
00101 <font class="keywordflow">return</font> (node->Flags & CFreeNode::Red) != 0;
00102 }
00103
00104 <font class="comment">// *********************************************************</font>
00105
00106 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::isNodeBlack (<font class="keyword">const</font> CFreeNode *node)
00107 {
00108 <font class="keywordflow">return</font> (node->Flags & CFreeNode::Red) == 0;
00109 }
00110
00111 <font class="comment">// *********************************************************</font>
00112
00113 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setNodeFree (CNodeBegin *node)
00114 {
00115 node->SizeAndFlags |= CNodeBegin::Free;
00116 }
00117
00118 <font class="comment">// *********************************************************</font>
00119
00120 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setNodeUsed (CNodeBegin *node)
00121 {
00122 node->SizeAndFlags &= ~CNodeBegin::Free;
00123 }
00124
00125 <font class="comment">// *********************************************************</font>
00126
00127 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setNodeLast (CNodeBegin *node, <font class="keywordtype">bool</font> last)
00128 {
00129 <font class="keywordflow">if</font> (last)
00130 node->SizeAndFlags |= CNodeBegin::Last;
00131 <font class="keywordflow">else</font>
00132 node->SizeAndFlags &= ~CNodeBegin::Last;
00133 }
00134
00135 <font class="comment">// *********************************************************</font>
00136
00137 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setNodeSize (CNodeBegin *node, uint size)
00138 {
00139 <font class="comment">// Size must be < 1 Go</font>
00140 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((size&0xc0000000) == 0);
00141
00142 <font class="comment">// Set the size</font>
00143 node->SizeAndFlags &= ~CNodeBegin::SizeMask;
00144 node->SizeAndFlags |= size;
00145 }
00146
00147 <font class="comment">// *********************************************************</font>
00148
00149 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setNodeColor (CFreeNode *node, <font class="keywordtype">bool</font> red)
00150 {
00151 <font class="keywordflow">if</font> (red)
00152 node->Flags |= CFreeNode::Red;
00153 <font class="keywordflow">else</font>
00154 node->Flags &= ~CFreeNode::Red;
00155 }
00156
00157 <font class="comment">// *********************************************************</font>
00158
00159 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setNodeRed (CFreeNode *node)
00160 {
00161 node->Flags |= CFreeNode::Red;
00162 }
00163
00164 <font class="comment">// *********************************************************</font>
00165
00166 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setNodeBlack (CFreeNode *node)
00167 {
00168 node->Flags &= ~CFreeNode::Red;
00169 }
00170
00171 <font class="comment">// *********************************************************</font>
00172 <font class="comment">// Free tree management</font>
00173 <font class="comment">// *********************************************************</font>
00174
00175 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::rotateLeft (CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
00176 {
00177 <font class="comment">// Rotate node x to left</font>
00178
00179 <font class="comment">// Establish x->Right link</font>
00180 CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Right;
00181 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Right = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Left;
00182 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Left != &_NullNode.FreeNode)
00183 {
00184 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Left->Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00185 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Left);
00186 }
00187
00188 <font class="comment">// Establish y->Parent link</font>
00189 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> != &_NullNode.FreeNode)
00190 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent;
00191
00192 <font class="comment">// x is the root ?</font>
00193 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent)
00194 {
00195 <font class="comment">// Link its parent to y</font>
00196 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Left)
00197 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Left = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00198 <font class="keywordflow">else</font>
00199 {
00200 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Right);
00201 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Right = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00202 }
00203 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00204 }
00205 <font class="keywordflow">else</font>
00206 {
00207 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == _FreeTreeRoot);
00208 _FreeTreeRoot = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00209 }
00210
00211 <font class="comment">// Link x and y</font>
00212 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Left = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00213 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> != &_NullNode.FreeNode)
00214 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00215 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00216 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00217 }
00218
00219 <font class="comment">// *********************************************************</font>
00220
00221 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::rotateRight (CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
00222 {
00223 <font class="comment">// Rotate node x to right</font>
00224
00225 <font class="comment">// Establish x->Left link</font>
00226 CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Left;
00227 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Left = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Right;
00228 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Right != &_NullNode.FreeNode)
00229 {
00230 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Right->Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00231 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Right);
00232 }
00233
00234 <font class="comment">// Establish y->parent link</font>
00235 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> != &_NullNode.FreeNode)
00236 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent;
00237
00238 <font class="comment">// x is the root ?</font>
00239 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent)
00240 {
00241 <font class="comment">// Link its parent to y</font>
00242 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Right)
00243 {
00244 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Right = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00245 }
00246 <font class="keywordflow">else</font>
00247 {
00248 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Left);
00249 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Left = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00250 }
00251 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00252 }
00253 <font class="keywordflow">else</font>
00254 {
00255 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == _FreeTreeRoot);
00256 _FreeTreeRoot = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00257 }
00258
00259 <font class="comment">// Link x and y</font>
00260 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Right = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00261 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> != &_NullNode.FreeNode)
00262 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00263
00264 <font class="comment">// Crc</font>
00265 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00266 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00267 }
00268
00269 <font class="comment">// *********************************************************</font>
00270
00271 <font class="keyword">inline</font> CHeapAllocator::CFreeNode *CHeapAllocator::find (uint size)
00272 {
00273 CHeapAllocator::CFreeNode *current = _FreeTreeRoot;
00274 CHeapAllocator::CFreeNode *smallest = NULL;
00275 <font class="keywordflow">while</font> (current != &_NullNode.FreeNode)
00276 {
00277 <font class="comment">// Smaller than this node ?</font>
00278 <font class="keywordflow">if</font> (size <= getNodeSize (getNode (current)))
00279 {
00280 <font class="comment">// This is good</font>
00281 smallest = current;
00282
00283 <font class="comment">// Go left</font>
00284 current = current->Left;
00285 }
00286 <font class="keywordflow">else</font>
00287 {
00288 <font class="comment">// Go right</font>
00289 current = current->Right;
00290 }
00291 }
00292 <font class="keywordflow">return</font> smallest;
00293 }
00294
00295 <font class="comment">// *********************************************************</font>
00296 <font class="comment">// Node methods</font>
00297 <font class="comment">// *********************************************************</font>
00298
00299 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00300 <font class="preprocessor"></font>
00301 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::computeCRC32(uint32 &crc, <font class="keyword">const</font> <font class="keywordtype">void</font>* buffer, <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> count)
00302 {
00303 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ( (count&3) == 0);
00304 count >>= 2;
00305
00306 <font class="keyword">const</font> uint32* ptr = (uint32*) buffer;
00307 <font class="keywordflow">while</font> (count--)
00308 {
00309 crc ^= *(ptr++);
00310 }
00311 <font class="comment">/* Real CRC, too slow</font>
00312 <font class="comment"> </font>
00313 <font class="comment"> const uint8* ptr = (uint8*) buffer;</font>
00314 <font class="comment"> while (count--)</font>
00315 <font class="comment"> {</font>
00316 <font class="comment"> uint8 value = *(ptr++);</font>
00317 <font class="comment"> crc ^= ((uint)value << 24);</font>
00318 <font class="comment"> for (int i = 0; i < 8; i++)</font>
00319 <font class="comment"> {</font>
00320 <font class="comment"> if (crc & 0x80000000)</font>
00321 <font class="comment"> {</font>
00322 <font class="comment"> crc = (crc << 1) ^ 0x04C11DB7;</font>
00323 <font class="comment"> }</font>
00324 <font class="comment"> else</font>
00325 <font class="comment"> {</font>
00326 <font class="comment"> crc <<= 1;</font>
00327 <font class="comment"> }</font>
00328 <font class="comment"> }</font>
00329 <font class="comment"> }</font>
00330 <font class="comment">*/</font>
00331 }
00332
00333 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00334 <font class="preprocessor"></font>
00335 <font class="comment">// *********************************************************</font>
00336
00337 <font class="keyword">inline</font> <font class="keyword">const</font> CHeapAllocator::CNodeBegin *CHeapAllocator::getFirstNode (<font class="keyword">const</font> CMainBlock *mainBlock)
00338 {
00339 <font class="comment">// Align the node pointer</font>
00340 <font class="keywordflow">return</font> (CNodeBegin*)(((uint32)mainBlock->Ptr&~(Align-1)) + ((((uint32)mainBlock->Ptr&(Align-1))==0)? 0 : Align));
00341 }
00342
00343 <font class="comment">// *********************************************************</font>
00344
00345 <font class="keyword">inline</font> CHeapAllocator::CNodeBegin *CHeapAllocator::getFirstNode (CMainBlock *mainBlock)
00346 {
00347 <font class="comment">// todo align</font>
00348 <font class="keywordflow">return</font> (CNodeBegin*)(((uint32)mainBlock->Ptr&~(Align-1)) + ((((uint32)mainBlock->Ptr&(Align-1))==0)? 0 : Align));
00349 }
00350
00351 <font class="comment">// *********************************************************</font>
00352
00353 <font class="keyword">inline</font> <font class="keyword">const</font> CHeapAllocator::CNodeBegin *CHeapAllocator::getNextNode (<font class="keyword">const</font> CNodeBegin *current)
00354 {
00355 <font class="comment">// Last ?</font>
00356 <font class="keywordflow">if</font> (isNodeLast (current))
00357 <font class="keywordflow">return</font> NULL;
00358
00359 <font class="comment">// todo align</font>
00360 <font class="keywordflow">return</font> (<font class="keyword">const</font> CNodeBegin*)((uint8*)current + <font class="keyword">sizeof</font> (CNodeBegin) + NL_HEAP_NODE_END_SIZE + getNodeSize (current) );
00361 }
00362
00363 <font class="comment">// *********************************************************</font>
00364
00365 <font class="keyword">inline</font> CHeapAllocator::CNodeBegin *CHeapAllocator::getNextNode (CNodeBegin *current)
00366 {
00367 <font class="comment">// Last ?</font>
00368 <font class="keywordflow">if</font> (isNodeLast (current))
00369 <font class="keywordflow">return</font> NULL;
00370
00371 <font class="comment">// todo align</font>
00372 <font class="keywordflow">return</font> (CNodeBegin*)((uint8*)current + <font class="keyword">sizeof</font> (CNodeBegin) + NL_HEAP_NODE_END_SIZE + getNodeSize (current) );
00373 }
00374
00375 <font class="comment">// *********************************************************</font>
00376
00377 <font class="keyword">inline</font> <font class="keyword">const</font> CHeapAllocator::CFreeNode *CHeapAllocator::getFreeNode (<font class="keyword">const</font> CNodeBegin *current)
00378 {
00379 <font class="keywordflow">return</font> (<font class="keyword">const</font> CHeapAllocator::CFreeNode *)((uint8*)current + <font class="keyword">sizeof</font>(CNodeBegin));
00380 }
00381
00382 <font class="comment">// *********************************************************</font>
00383
00384 <font class="keyword">inline</font> CHeapAllocator::CFreeNode *CHeapAllocator::getFreeNode (CNodeBegin *current)
00385 {
00386 <font class="keywordflow">return</font> (CHeapAllocator::CFreeNode *)((uint8*)current + <font class="keyword">sizeof</font>(CNodeBegin));
00387 }
00388
00389 <font class="comment">// *********************************************************</font>
00390
00391 <font class="keyword">inline</font> <font class="keyword">const</font> CHeapAllocator::CNodeBegin *CHeapAllocator::getNode (<font class="keyword">const</font> CFreeNode *current)
00392 {
00393 <font class="keywordflow">return</font> (<font class="keyword">const</font> CHeapAllocator::CNodeBegin *)((uint8*)current - <font class="keyword">sizeof</font>(CNodeBegin));
00394 }
00395
00396 <font class="comment">// *********************************************************</font>
00397
00398 <font class="keyword">inline</font> CHeapAllocator::CNodeBegin *CHeapAllocator::getNode (CFreeNode *current)
00399 {
00400 <font class="keywordflow">return</font> (CHeapAllocator::CNodeBegin *)((uint8*)current - <font class="keyword">sizeof</font>(CNodeBegin));
00401 }
00402
00403 <font class="comment">// *********************************************************</font>
00404
00405 <font class="keyword">inline</font> uint CHeapAllocator::getNodeSize (<font class="keyword">const</font> CNodeBegin *current)
00406 {
00407 <font class="keywordflow">return</font> current->SizeAndFlags & CNodeBegin::SizeMask;
00408 }
00409
00410 <font class="comment">// *********************************************************</font>
00411
00412 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00413 <font class="preprocessor"></font>
00414 <font class="keyword">inline</font> uint32 CHeapAllocator::evalMagicNumber (<font class="keyword">const</font> CNodeBegin *node)
00415 {
00416 uint32 crc = (uint32)node;
00417
00418 <font class="comment">// Make the CRC of the rest of the node header</font>
00419 computeCRC32 (crc, node, <font class="keyword">sizeof</font>(CNodeBegin));
00420
00421 <font class="comment">// If the node is free and LARGE, crc the free tree node</font>
00422 <font class="keywordflow">if</font> ( isNodeFree (node) && !isNodeSmall (node) )
00423 computeCRC32 (crc, getFreeNode (node), <font class="keyword">sizeof</font>(CFreeNode));
00424
00425 <font class="comment">// Return the magic number</font>
00426 <font class="keywordflow">return</font> crc;
00427 }
00428
00429 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00430 <font class="preprocessor"></font>
00431 <font class="comment">// *********************************************************</font>
00432 <font class="comment">// Integrity checks</font>
00433 <font class="comment">// *********************************************************</font>
00434
00435 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::checkNodeSB (<font class="keyword">const</font> CSmallBlockPool *mainBlock, <font class="keyword">const</font> CNodeBegin *previous, <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>
00436 <font class="keyword"></font>{
00437 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00438 <font class="preprocessor"></font> <font class="comment">// Get the theorical CRC check</font>
00439 uint32 crc = evalMagicNumber (current);
00440
00441 <font class="comment">// Compare the magic number</font>
00442 <font class="keywordflow">if</font> (*(current->EndMagicNumber) != crc)
00443 {
00444 <font class="comment">// Stop on error ?</font>
00445 <font class="keywordflow">if</font> (stopOnError)
00446 {
00447 <font class="comment">// ********</font>
00448 <font class="comment">// * STOP *</font>
00449 <font class="comment">// ********</font>
00450 <font class="comment">// * The bottom CRC32 of the current node is wrong: Check if a node has overflowed. Node by top and bottom,</font>
00451 <font class="comment">// * the next by the top and the previous by the bottom.</font>
00452 <font class="comment">// * overflow or the next node by the top.</font>
00453 <font class="comment">// ********</font>
00454 <font class="comment">// * (*previous): previous node</font>
00455 <font class="comment">// * (*current): current node</font>
00456 <font class="comment">// * (*next): next node</font>
00457 <font class="comment">// ********</font>
00458 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00459 }
00460
00461 <font class="comment">// CRC is wrong</font>
00462 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00463 }
00464 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00465 <font class="preprocessor"></font>
00466 <font class="comment">// *** Release node control</font>
00467
00468 <font class="comment">// Check node</font>
00469 <font class="keywordflow">if</font> (
00470 ( (uint)current < ((uint)mainBlock) + <font class="keyword">sizeof</font> (CSmallBlockPool)) ||
00471 ( (uint)current + getNodeSize (current) + <font class="keyword">sizeof</font>(CNodeBegin) + NL_HEAP_NODE_END_SIZE >
00472 ((uint)mainBlock) + <font class="keyword">sizeof</font> (CSmallBlockPool) + SmallBlockPoolSize * (<font class="keyword">sizeof</font>(CNodeBegin)+ mainBlock->Size + NL_HEAP_NODE_END_SIZE) )
00473 )
00474 {
00475 <font class="comment">// Stop on error ?</font>
00476 <font class="keywordflow">if</font> (stopOnError)
00477 {
00478 <font class="comment">// ********</font>
00479 <font class="comment">// * STOP *</font>
00480 <font class="comment">// ********</font>
00481 <font class="comment">// * The size value is corrupted: Check if the current node has</font>
00482 <font class="comment">// * overflow by the top or the previous node by the bottom.</font>
00483 <font class="comment">// ********</font>
00484 <font class="comment">// * (*previous): previous node</font>
00485 <font class="comment">// * (*current): current node</font>
00486 <font class="comment">// * (*next): next node</font>
00487 <font class="comment">// ********</font>
00488 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00489 }
00490
00491 <font class="comment">// Node size is corrupted</font>
00492 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00493 }
00494
00495 <font class="comment">// Ok</font>
00496 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00497 }
00498
00499 <font class="comment">// *********************************************************</font>
00500
00501 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::checkNodeLB (<font class="keyword">const</font> CMainBlock *mainBlock, <font class="keyword">const</font> CNodeBegin *previous, <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>
00502 <font class="keyword"></font>{
00503 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00504 <font class="preprocessor"></font> <font class="comment">// Get the theorical CRC check</font>
00505 uint32 crc = evalMagicNumber (current);
00506
00507 <font class="comment">// Compare the magic number</font>
00508 <font class="keywordflow">if</font> (*(current->EndMagicNumber) != crc)
00509 {
00510 <font class="comment">// Stop on error ?</font>
00511 <font class="keywordflow">if</font> (stopOnError)
00512 {
00513 <font class="comment">// ********</font>
00514 <font class="comment">// * STOP *</font>
00515 <font class="comment">// ********</font>
00516 <font class="comment">// * The bottom CRC32 of the current node is wrong: Check if a node has overflowed. Node by top and bottom,</font>
00517 <font class="comment">// * the next by the top and the previous by the bottom.</font>
00518 <font class="comment">// * overflow or the next node by the top.</font>
00519 <font class="comment">// ********</font>
00520 <font class="comment">// * (*previous): previous node</font>
00521 <font class="comment">// * (*current): current node</font>
00522 <font class="comment">// * (*next): next node</font>
00523 <font class="comment">// ********</font>
00524 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00525 }
00526
00527 <font class="comment">// CRC is wrong</font>
00528 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00529 }
00530 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00531 <font class="preprocessor"></font>
00532 <font class="comment">// *** Release node control</font>
00533
00534 <font class="comment">// Check node</font>
00535 <font class="keywordflow">if</font> (
00536 ( (uint)current < (uint)mainBlock->Ptr ) ||
00537 ( (uint)current + getNodeSize (current) + <font class="keyword">sizeof</font>(CNodeBegin) + NL_HEAP_NODE_END_SIZE >
00538 (uint)mainBlock->Ptr + mainBlock->Size )
00539 )
00540 {
00541 <font class="comment">// Stop on error ?</font>
00542 <font class="keywordflow">if</font> (stopOnError)
00543 {
00544 <font class="comment">// ********</font>
00545 <font class="comment">// * STOP *</font>
00546 <font class="comment">// ********</font>
00547 <font class="comment">// * The size value is corrupted: Check if the current node has</font>
00548 <font class="comment">// * overflow by the top or the previous node by the bottom.</font>
00549 <font class="comment">// ********</font>
00550 <font class="comment">// * (*previous): previous node</font>
00551 <font class="comment">// * (*current): current node</font>
00552 <font class="comment">// * (*next): next node</font>
00553 <font class="comment">// ********</font>
00554 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00555 }
00556
00557 <font class="comment">// Node size is corrupted</font>
00558 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00559 }
00560
00561 <font class="comment">// Check Previous node pointer</font>
00562 <font class="keywordflow">if</font> ( !(current->Previous == NULL ||
00563 ( ((uint)current->Previous <= (uint)current - <font class="keyword">sizeof</font> (CNodeBegin) - NL_HEAP_NODE_END_SIZE) &&
00564 ((uint)current->Previous >= (uint)mainBlock->Ptr) )
00565 ) )
00566 {
00567 <font class="comment">// Stop on error ?</font>
00568 <font class="keywordflow">if</font> (stopOnError)
00569 {
00570 <font class="comment">// ********</font>
00571 <font class="comment">// * STOP *</font>
00572 <font class="comment">// ********</font>
00573 <font class="comment">// * The previous value is corrupted: Check if the current node has</font>
00574 <font class="comment">// * overflow by the top or the previous node by the bottom.</font>
00575 <font class="comment">// ********</font>
00576 <font class="comment">// * (*previous): previous node</font>
00577 <font class="comment">// * (*current): current node</font>
00578 <font class="comment">// * (*next): next node</font>
00579 <font class="comment">// ********</font>
00580 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00581 }
00582
00583 <font class="comment">// Node flag is corrupted</font>
00584 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00585 }
00586
00587 <font class="comment">// Check FreeNode node pointer</font>
00588 <font class="keywordflow">if</font> (isNodeFree (current))
00589 {
00590 <font class="comment">// Get only this free node</font>
00591 <font class="keyword">const</font> CFreeNode *freeNode = getFreeNode (current);
00592 checkFreeNode (freeNode, stopOnError, <font class="keyword">false</font>);
00593 }
00594
00595 <font class="comment">// Ok</font>
00596 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00597 }
00598
00599 <font class="comment">// *********************************************************</font>
00600
00601 <font class="keyword">inline</font> <font class="keywordtype">bool</font> CHeapAllocator::checkFreeNode (<font class="keyword">const</font> CFreeNode *current, <font class="keywordtype">bool</font> stopOnError, <font class="keywordtype">bool</font> recurse)<font class="keyword"> const</font>
00602 <font class="keyword"></font>{
00603 <font class="comment">// Not NULL ?</font>
00604 <font class="keywordflow">if</font> (current != &_NullNode.FreeNode)
00605 {
00606 <font class="comment">// Get the node</font>
00607 <font class="keyword">const</font> CNodeBegin *node = getNode (current);
00608
00609 <font class="comment">// 1st rule: Node must be free</font>
00610 <font class="keywordflow">if</font> ( !isNodeFree(node) )
00611 {
00612 <font class="comment">// Stop on error ?</font>
00613 <font class="keywordflow">if</font> (stopOnError)
00614 {
00615 <font class="comment">// ********</font>
00616 <font class="comment">// * STOP *</font>
00617 <font class="comment">// ********</font>
00618 <font class="comment">// * Node should be free : Free tree is corrupted.</font>
00619 <font class="comment">// ********</font>
00620 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00621 }
00622
00623 <font class="comment">// Node Color is corrupted</font>
00624 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00625 }
00626
00627 <font class="comment">// 2nd rule: Node must be sorted </font>
00628 <font class="keywordflow">if</font> (
00629 ( current->Left != &_NullNode.FreeNode && getNodeSize (getNode (current->Left)) > getNodeSize (node) ) ||
00630 ( current->Right != &_NullNode.FreeNode && getNodeSize (getNode (current->Right)) < getNodeSize (node) )
00631 )
00632 {
00633 <font class="comment">// Stop on error ?</font>
00634 <font class="keywordflow">if</font> (stopOnError)
00635 {
00636 <font class="comment">// ********</font>
00637 <font class="comment">// * STOP *</font>
00638 <font class="comment">// ********</font>
00639 <font class="comment">// * Node order is corrupted: Free tree is corrupted.</font>
00640 <font class="comment">// ********</font>
00641 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00642 }
00643
00644 <font class="comment">// Node Data is corrupted</font>
00645 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00646 }
00647
00648 <font class="comment">// 3rd rule: if red, must have two black nodes</font>
00649 <font class="keywordtype">bool</font> leftBlack = (current->Left == &_NullNode.FreeNode) || isNodeBlack(current->Left);
00650 <font class="keywordtype">bool</font> rightBlack = (current->Right == &_NullNode.FreeNode) || isNodeBlack(current->Right);
00651 <font class="keywordflow">if</font> ( !leftBlack && !rightBlack && isNodeRed (getFreeNode (node)) )
00652 {
00653 <font class="comment">// Stop on error ?</font>
00654 <font class="keywordflow">if</font> (stopOnError)
00655 {
00656 <font class="comment">// ********</font>
00657 <font class="comment">// * STOP *</font>
00658 <font class="comment">// ********</font>
00659 <font class="comment">// * Color is corrupted: Free tree is corrupted.</font>
00660 <font class="comment">// ********</font>
00661 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00662 }
00663
00664 <font class="comment">// Node Color is corrupted</font>
00665 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00666 }
00667
00668 <font class="comment">// If Parent NULL, must be the root</font>
00669 <font class="keywordflow">if</font> ( ( (current->Parent == NULL) && (_FreeTreeRoot != current) ) || ( (current->Parent != NULL) && (_FreeTreeRoot == current) ) )
00670 {
00671 <font class="comment">// Stop on error ?</font>
00672 <font class="keywordflow">if</font> (stopOnError)
00673 {
00674 <font class="comment">// ********</font>
00675 <font class="comment">// * STOP *</font>
00676 <font class="comment">// ********</font>
00677 <font class="comment">// * Parent pointer corrupted: Free tree is corrupted.</font>
00678 <font class="comment">// ********</font>
00679 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a3">NL_ALLOC_STOP</a>;
00680 }
00681
00682 <font class="comment">// Node Parent is corrupted</font>
00683 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00684 }
00685
00686 <font class="comment">// Recuse childern</font>
00687 <font class="keywordflow">if</font> (recurse)
00688 {
00689 <font class="keywordflow">if</font> (!checkFreeNode (current->Left, stopOnError, recurse))
00690 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00691 <font class="keywordflow">if</font> (!checkFreeNode (current->Right, stopOnError, recurse))
00692 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00693 }
00694 }
00695
00696 <font class="comment">// Ok</font>
00697 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00698 }
00699
00700 <font class="comment">// *********************************************************</font>
00701 <font class="comment">// Synchronisation methods</font>
00702 <font class="comment">// *********************************************************</font>
00703
00704 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::enterCriticalSectionSB ()<font class="keyword"> const</font>
00705 <font class="keyword"></font>{
00706 _MutexSB.enter ();
00707 }
00708
00709 <font class="comment">// *********************************************************</font>
00710
00711 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::leaveCriticalSectionSB ()<font class="keyword"> const</font>
00712 <font class="keyword"></font>{
00713 _MutexSB.leave ();
00714 }
00715
00716 <font class="comment">// *********************************************************</font>
00717
00718 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::enterCriticalSectionLB ()<font class="keyword"> const</font>
00719 <font class="keyword"></font>{
00720 _MutexLB.enter ();
00721 }
00722
00723 <font class="comment">// *********************************************************</font>
00724
00725 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::leaveCriticalSectionLB ()<font class="keyword"> const</font>
00726 <font class="keyword"></font>{
00727 _MutexLB.leave ();
00728 }
00729
00730 <font class="comment">// *********************************************************</font>
00731
00732 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::enterCriticalSection ()<font class="keyword"> const</font>
00733 <font class="keyword"></font>{
00734 enterCriticalSectionSB ();
00735 enterCriticalSectionLB ();
00736 }
00737
00738 <font class="comment">// *********************************************************</font>
00739
00740 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::leaveCriticalSection ()<font class="keyword"> const</font>
00741 <font class="keyword"></font>{
00742 leaveCriticalSectionLB ();
00743 leaveCriticalSectionSB ();
00744 }
00745
00746 <font class="comment">// *********************************************************</font>
00747
00748
00749
00750
00751
00752
00753 <font class="comment">// *********************************************************</font>
00754 <font class="comment">// *********************************************************</font>
00755
00756 <font class="comment">// Synchronized methods</font>
00757
00758 <font class="comment">// *********************************************************</font>
00759 <font class="comment">// *********************************************************</font>
00760
00761
00762
00763
00764
00765
00766
00767 <font class="comment">// *********************************************************</font>
00768
00769 <font class="keyword">inline</font> uint CHeapAllocator::getMainBlockCount ()<font class="keyword"> const</font>
00770 <font class="keyword"></font>{
00771 uint count = 0;
00772 CMainBlock *currentBlock = _MainBlockList;
00773 <font class="keywordflow">while</font> (currentBlock)
00774 {
00775 currentBlock = currentBlock->Next;
00776 count++;
00777 }
00778 <font class="keywordflow">return</font> count;
00779 }
00780
00781 <font class="comment">// *********************************************************</font>
00782 <font class="comment">// Debug functions</font>
00783 <font class="comment">// *********************************************************</font>
00784
00785 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00786 <font class="preprocessor"></font>
00787 <font class="comment">/*inline void CHeapAllocator::debugAddBreakpoint (uint32 allocateNumber)</font>
00788 <font class="comment">{</font>
00789 <font class="comment"> _Breakpoints.insert (allocateNumber);</font>
00790 <font class="comment">}*/</font>
00791
00792 <font class="comment">// *********************************************************</font>
00793
00794 <font class="comment">/*inline void CHeapAllocator::debugRemoveBreakpoints ()</font>
00795 <font class="comment">{</font>
00796 <font class="comment"> _Breakpoints.clear ();</font>
00797 <font class="comment">}*/</font>
00798
00799 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00800 <font class="preprocessor"></font>
00801 <font class="comment">// *********************************************************</font>
00802
00803 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setOutOfMemoryMode (TOutOfMemoryMode mode)
00804 {
00805 enterCriticalSection ();
00806
00807 _OutOfMemoryMode = mode;
00808
00809 leaveCriticalSection ();
00810 }
00811
00812 <font class="comment">// *********************************************************</font>
00813
00814 <font class="keyword">inline</font> CHeapAllocator::TOutOfMemoryMode CHeapAllocator::getOutOfMemoryMode ()<font class="keyword"> const</font>
00815 <font class="keyword"></font>{
00816 <font class="keywordflow">return</font> _OutOfMemoryMode;
00817 }
00818
00819 <font class="comment">// *********************************************************</font>
00820
00821 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setBlockAllocationMode (TBlockAllocationMode mode)
00822 {
00823 enterCriticalSection ();
00824
00825 _BlockAllocationMode = mode;
00826
00827 leaveCriticalSection ();
00828 }
00829
00830 <font class="comment">// *********************************************************</font>
00831
00832 <font class="keyword">inline</font> CHeapAllocator::TBlockAllocationMode CHeapAllocator::getBlockAllocationMode ()<font class="keyword"> const</font>
00833 <font class="keyword"></font>{
00834 <font class="keywordflow">return</font> _BlockAllocationMode;
00835 }
00836
00837 <font class="comment">// *********************************************************</font>
00838
00839
00840 <font class="keyword">inline</font> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="zone__lighter_8cpp.html#a11">CHeapAllocator::getName</a> ()<font class="keyword"> const</font>
00841 <font class="keyword"></font>{
00842 <font class="keywordflow">return</font> _Name;
00843 }
00844
00845 <font class="comment">// *********************************************************</font>
00846
00847 <font class="keyword">inline</font> uint CHeapAllocator::getMainBlockSize ()<font class="keyword"> const</font>
00848 <font class="keyword"></font>{
00849 <font class="keywordflow">return</font> _MainBlockSize;
00850 }
00851
00852
00853 <font class="comment">// *********************************************************</font>
00854 <font class="comment">// Small Block</font>
00855 <font class="comment">// *********************************************************</font>
00856
00857 <font class="keyword">inline</font> CHeapAllocator::CNodeBegin *CHeapAllocator::getSmallBlock (CHeapAllocator::CSmallBlockPool *smallBlock, uint blockIndex)
00858 {
00859 <font class="keywordflow">return</font> (CHeapAllocator::CNodeBegin*)((uint8*)smallBlock + <font class="keyword">sizeof</font> (CSmallBlockPool) + blockIndex * (<font class="keyword">sizeof</font>(CNodeBegin) + smallBlock->Size + NL_HEAP_NODE_END_SIZE) );
00860 }
00861
00862 <font class="comment">// *********************************************************</font>
00863
00864 <font class="keyword">inline</font> CHeapAllocator::CNodeBegin *CHeapAllocator::getNextSmallBlock (CNodeBegin *previous)
00865 {
00866 <font class="keywordflow">return</font> previous->Previous;
00867 }
00868
00869 <font class="comment">// *********************************************************</font>
00870
00871 <font class="keyword">inline</font> <font class="keywordtype">void</font> CHeapAllocator::setNextSmallBlock (CNodeBegin *previous, CNodeBegin *next)
00872 {
00873 previous->Previous = next;
00874 }
00875
00876 <font class="comment">// *********************************************************</font>
00877
00878 <font class="comment">/*</font>
00879 <font class="comment">void *reallocate (void *ptr, uint size, const char *sourceFile, uint line, const char *category);</font>
00880 <font class="comment">void freeAll ();</font>
00881 <font class="comment">void releaseMemory ();</font>
00882 <font class="comment">void setMainBlockSize (uint mainBlockSize);</font>
00883 <font class="comment">uint getMainBlockSize () const;</font>
00884 <font class="comment">bool setMainBlockCount (uint blockCount);</font>
00885 <font class="comment">uint debugGetDebugInfoSize () const;</font>
00886 <font class="comment">uint debugGetAllocatedMemoryByCatgegory (const char* category) const;</font>
00887 <font class="comment">void debugReportMemoryLeak (std::vector<CMemoryLeakBlock> &result);</font>
00888 <font class="comment">*/</font>
00889
00890 <font class="preprocessor">#endif // NL_HEAP_ALLOCATOR_H</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|