aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/memory_2heap__allocator_8cpp-source.html
blob: c461f2ab9d8532ceed136f7c5ce6559169c1cf6d (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
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
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
<!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.cpp</h1><a href="memory_2heap__allocator_8cpp.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="comment">/*      This file can't use Visual precompilated headers because</font>
00027 <font class="comment">        the precompilated header ("nel/misc/stdmisc.h") includes </font>
00028 <font class="comment">        "nel/misc/types_nl.h". Before including the file </font>
00029 <font class="comment">        "nel/misc/types_nl.h", we need to define NL_HEAP_ALLOCATOR_H</font>
00030 <font class="comment">        for this file to avoid new overriding. */</font>
00031 
00032 <font class="preprocessor">#include "<a class="code" href="src_2memory_2heap__allocator_8h.html">heap_allocator.h</a>"</font>
00033 
00034 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00035 
00036 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00037 <font class="preprocessor"></font><font class="preprocessor">#include &lt;windows.h&gt;</font>
00038 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00039 <font class="preprocessor"></font>
<a name="l00040"></a><a class="code" href="namespaceNLMEMORY.html">00040</a> <font class="keyword">namespace </font>NLMEMORY 
00041 {
00042 
00043 <font class="comment">// Include inlines functions</font>
00044 <font class="preprocessor">#include "<a class="code" href="src_2memory_2heap__allocator__inline_8h.html">heap_allocator_inline.h</a>"</font>
00045 
00046 <font class="preprocessor">#define NL_HEAP_SB_CATEGORY "_SmlBlk"</font>
00047 <font class="preprocessor"></font><font class="preprocessor">#define NL_HEAP_CATEGORY_BLOCK_CATEGORY "_MemCat"</font>
00048 <font class="preprocessor"></font><font class="preprocessor">#define NL_HEAP_MEM_DEBUG_CATEGORY "_MemDb"</font>
00049 <font class="preprocessor"></font><font class="preprocessor">#define NL_HEAP_UNKNOWN_CATEGORY "Unknown"</font>
00050 <font class="preprocessor"></font>
00051 <font class="keywordtype">void</font> <a class="code" href="namespaceNLMEMORY.html#a2">CHeapAllocatorOutputError</a> (<font class="keyword">const</font> <font class="keywordtype">char</font> *str)
00052 {
00053         fprintf (stderr, str);
00054 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00055 <font class="preprocessor"></font>        OutputDebugString (str);
00056 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00057 <font class="preprocessor"></font>}
00058 
00059 <font class="comment">// *********************************************************</font>
00060 <font class="comment">// Constructors / desctrutors</font>
00061 <font class="comment">// *********************************************************</font>
00062 
00063 CHeapAllocator::CHeapAllocator (uint mainBlockSize, uint blockCount, TBlockAllocationMode blockAllocationMode, 
00064                                   TOutOfMemoryMode outOfMemoryMode)
00065 {
00066         <font class="comment">// Critical section</font>
00067         enterCriticalSection ();
00068 
00069         <font class="comment">// Allocator name</font>
00070         _Name[0] = 0;
00071 
00072         <font class="comment">// Check size of structures must be aligned</font>
00073         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((<font class="keyword">sizeof</font> (CNodeBegin) &amp; (Align-1)) == 0);
00074         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((NL_HEAP_NODE_END_SIZE &amp; (Align-1)) == 0);
00075         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((<font class="keyword">sizeof</font> (CFreeNode) &amp; (Align-1)) == 0);
00076 
00077         <font class="comment">// Check small block sizes</font>
00078         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((FirstSmallBlock&amp;(SmallBlockGranularity-1)) == 0);
00079         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((LastSmallBlock&amp;(SmallBlockGranularity-1)) == 0);
00080 
00081         _MainBlockList = NULL;
00082         _MainBlockSize = mainBlockSize;
00083         _BlockCount = blockCount;
00084         _BlockAllocationMode = blockAllocationMode;
00085         _OutOfMemoryMode = outOfMemoryMode;
00086         _FreeTreeRoot = &amp;_NullNode.FreeNode;
00087 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00088 <font class="preprocessor"></font>        _AlwaysCheck = <font class="keyword">false</font>;
00089 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00090 <font class="preprocessor"></font>
00091         _NullNode.FreeNode.Left = &amp;_NullNode.FreeNode;
00092         _NullNode.FreeNode.Right = &amp;_NullNode.FreeNode;
00093         _NullNode.FreeNode.Parent = NULL;
00094 
00095         setNodeBlack (&amp;_NullNode.FreeNode);
00096 
00097 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00098 <font class="preprocessor"></font>        _AllocateCount = 0;
00099 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00100 <font class="preprocessor"></font>
00101         <font class="comment">// *********************************************************</font>
00102         <font class="comment">// Small Block</font>
00103         <font class="comment">// *********************************************************</font>
00104 
00105         <font class="comment">// The free smallblock array by size</font>
00106         <font class="keyword">const</font> uint smallBlockSizeCount = NL_SMALLBLOCK_COUNT;
00107         uint smallBlockSize;
00108         <font class="keywordflow">for</font> (smallBlockSize=0; smallBlockSize&lt;smallBlockSizeCount; smallBlockSize++)
00109         {
<a name="l00110"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">00110</a>                 _FreeSmallBlocks[smallBlockSize] = NULL;
00111         }
00112 
00113         <font class="comment">// No small block</font>
00114         _SmallBlockPool = NULL;
00115 
00116         leaveCriticalSection ();
<a name="l00117"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">00117</a> }
00118 
00119 <font class="comment">// *********************************************************</font>
00120 
00121 CHeapAllocator::~CHeapAllocator ()
00122 {
00123         <font class="comment">// Release all memory used</font>
<a name="l00124"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f10">00124</a>         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a4">releaseMemory</a> ();
00125 }
00126 
00127 <font class="comment">// *********************************************************</font>
00128 
00129 <font class="keywordtype">void</font> CHeapAllocator::insert (CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
00130 {
<a name="l00131"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f11">00131</a>     CHeapAllocator::CFreeNode *current, *parent;
00132 
00133     <font class="comment">// Find future parent</font>
00134         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>;
00135         parent = NULL;
00136         <font class="keywordflow">while</font> (current != &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>)
00137         {
00138                 parent = current;
00139                 current = (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f5">getNode</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)) &lt;= <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f5">getNode</a> (current)) ) ? current-&gt;<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CFreeNode.html#m0">Left</a> : current-&gt;<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CFreeNode.html#m1">Right</a>;
00140         }
00141 
<a name="l00142"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">00142</a>         <font class="comment">// Setup new node</font>
00143         <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent = parent;
00144         <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Left = &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
00145         <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Right = &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
00146         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00147 
00148         <font class="comment">// Insert node in tree</font>
<a name="l00149"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f13">00149</a>         <font class="keywordflow">if</font> (parent)
00150         {
00151                 <font class="keywordflow">if</font>(<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f5">getNode</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)) &lt;= <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f5">getNode</a> (parent)))
00152                         parent-&gt;Left = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00153                 <font class="keywordflow">else</font>
00154                         parent-&gt;Right = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00155                 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (parent);
<a name="l00156"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f14">00156</a>         }
00157         <font class="keywordflow">else</font>
00158         {
00159                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00160         }
00161 
00162         <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>);
<a name="l00163"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f15">00163</a> 
00164     <font class="comment">// Maintain Red-Black tree balance</font>
00165     <font class="comment">// After inserting node x</font>
00166         <font class="comment">// Check Red-Black properties</font>
00167 
00168         <font class="keywordflow">while</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> != <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> &amp;&amp; <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent))
00169         {
<a name="l00170"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f16">00170</a>                 <font class="comment">// We have a violation</font>
00171                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Parent-&gt;Left)
00172                 {
00173                         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>-&gt;Parent-&gt;Parent-&gt;Right;
00174                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>))
00175                         {
00176                                 <font class="comment">// Uncle is RED</font>
00177                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00178                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00179                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Parent);
<a name="l00180"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f17">00180</a> 
00181                                 <font class="comment">// Crc node</font>
00182                                 <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>);
00183                                 <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>-&gt;Parent);
00184                                 <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>-&gt;Parent-&gt;Parent);
00185 
00186                                 <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>-&gt;Parent-&gt;Parent;
00187                         }
00188                         <font class="keywordflow">else</font>
00189                         {
00190                 <font class="comment">// Uncle is Black</font>
00191                                 <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>-&gt;Parent-&gt;Right)
<a name="l00192"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f18">00192</a>                                 {
00193                     <font class="comment">// Make x a left child</font>
00194                                         <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>-&gt;Parent;
00195                     <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c1">rotateLeft</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00196                                 }
00197 
00198                                 <font class="comment">// Recolor and rotate</font>
00199                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00200                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Parent);
00201 
<a name="l00202"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">00202</a>                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c2">rotateRight</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Parent);
00203 
00204                                 <font class="comment">// Crc node</font>
00205                                 <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>-&gt;Parent);
00206                         }
00207                 }
00208                 <font class="keywordflow">else</font>
<a name="l00209"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">00209</a>                 {
00210                         <font class="comment">// Mirror image of above code</font>
00211                         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>-&gt;Parent-&gt;Parent-&gt;Left;
00212                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>))
00213                         {                
00214                                 <font class="comment">// Uncle is Red</font>
00215                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00216                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00217                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Parent);
<a name="l00218"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c1">00218</a> 
00219                                 <font class="comment">// Crc node</font>
00220                                 <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>);
00221                                 <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>-&gt;Parent);
00222                                 <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>-&gt;Parent-&gt;Parent);
00223 
00224                                 <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>-&gt;Parent-&gt;Parent;
00225                         }
00226                         <font class="keywordflow">else</font>
00227                         {
00228                 <font class="comment">// Uncle is Black</font>
00229                 <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>-&gt;Parent-&gt;Left) 
00230                                 {
00231                     <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>-&gt;Parent;                    
00232                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c2">rotateRight</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00233                 }
00234                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00235                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Parent);
00236 
00237                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c1">rotateLeft</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Parent);
00238 
00239                                 <font class="comment">// Crc node</font>
00240                                 <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>-&gt;Parent);
00241                         }        
00242                 }    
00243         }
00244     <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>);
00245 
00246         <font class="comment">// Crc node</font>
00247         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>);
00248 }
00249 
00250 <font class="comment">// *********************************************************</font>
00251 
00252 <font class="keywordtype">void</font> CHeapAllocator::erase (CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>)
00253 {
00254         CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, *<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00255         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>-&gt;Left == &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a> || <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>-&gt;Right == &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>)
00256         {
00257                 <font class="comment">// y has a NULL node as a child</font>
00258                 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>;
00259         }
00260         <font class="keywordflow">else</font>
00261         {
00262                 <font class="comment">// Find tree successor with a &amp;_NullNode.FreeNode node as a child</font>
00263                 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>-&gt;Right;
<a name="l00264"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c2">00264</a>                 <font class="keywordflow">while</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Left != &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>)
00265                         <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Left;
00266         }
00267         
00268         <font class="comment">// x is y's only child</font>
00269         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Left != &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>)
00270                 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Left;
00271         <font class="keywordflow">else</font>
00272                 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Right;
00273 
00274         <font class="comment">// Remove y from the parent chain</font>
00275         <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent;
00276 
00277         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent)
00278         {
00279                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent-&gt;Left)
00280                         <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent-&gt;Left = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00281                 <font class="keywordflow">else</font>
00282                 {
00283                         <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#a365">y</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent-&gt;Right);
00284                         <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent-&gt;Right = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00285                 }
00286                 <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>-&gt;Parent);
00287         }
00288         <font class="keywordflow">else</font>
00289                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00290 
00291         <font class="keywordtype">bool</font> yRed = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00292 
00293         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> != <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>)
00294         {
00295                 <font class="comment">// Replace y by z</font>
00296                 *<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = *<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>;
00297                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f18">setNodeColor</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>));
00298                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent)
00299                 {
00300                         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent-&gt;Left == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>)
00301                         {
00302                                 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent-&gt;Left = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00303                         }
00304                         <font class="keywordflow">else</font>
00305                         {
00306                                 <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#a365">y</a>-&gt;Parent-&gt;Right == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>);
00307                                 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent-&gt;Right = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00308                         }
00309                 }
00310                 <font class="keywordflow">else</font>
00311                 {
00312                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>);
00313                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
<a name="l00314"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c5">00314</a>                 }
00315 
00316                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Left)
00317                 {
00318                         <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#a365">y</a>-&gt;Left-&gt;Parent == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>);
00319                         <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Left-&gt;Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00320                         
00321                         <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>-&gt;Left);
00322                 }
00323                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Right)
00324                 {
00325                         <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#a365">y</a>-&gt;Right-&gt;Parent == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>);
00326                         <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Right-&gt;Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00327         
00328                         <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>-&gt;Right);
00329                 }
00330         }
00331 
00332         <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>);
00333         <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>);
00334         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-&gt;Parent)
00335                 <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>-&gt;Parent);
00336 
00337         <font class="keywordflow">if</font> (!yRed)
00338         {
00339                 <font class="comment">// Maintain Red-Black tree balance</font>
00340                 <font class="comment">// After deleting node x</font>
00341                 <font class="keywordflow">while</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> != <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> &amp;&amp; <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>))
00342                 {
00343                         <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>-&gt;Parent-&gt;Left)
<a name="l00344"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f24">00344</a>                         {
00345                                 CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Right;
00346                                 <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>))
00347                                 {
00348                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00349                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00350                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c1">rotateLeft</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00351 
00352                                         <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#a367">w</a>);
00353 
00354                                         <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Right;
00355                                 }
00356                                 <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Left) &amp;&amp; <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Right))
00357                                 {
00358                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00359                                         <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>-&gt;Parent;
00360 
00361                                         <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#a367">w</a>);
00362                                 }
00363                                 <font class="keywordflow">else</font>
00364                                 {
00365                                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Right))
00366                                         {
00367                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Left);
00368                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00369                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c2">rotateRight</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00370                                                 <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Right;
00371                                         }
00372                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f18">setNodeColor</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent));
00373                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00374                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Right);
00375                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c1">rotateLeft</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00376 
00377                                         <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#a367">w</a>);
00378                                         <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#a367">w</a>-&gt;Right);
00379 
<a name="l00380"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">00380</a>                                         <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>;
00381                                 }
00382                         }
00383                         <font class="keywordflow">else</font>
00384                         {
00385                                 CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Left;
00386                                 <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>))
00387                                 {
<a name="l00388"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f22">00388</a>                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00389                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00390                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c2">rotateRight</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00391 
00392                                         <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#a367">w</a>);
00393 
00394                                         <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Left;
00395                                 }
<a name="l00396"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">00396</a>                                 <font class="keywordflow">if</font> ( <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Right) &amp;&amp; <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Left) )
00397                                 {
00398                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00399                                         <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>-&gt;Parent;
00400 
00401                                         <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#a367">w</a>);
00402                                 }
00403                                 <font class="keywordflow">else</font>
00404                                 {
00405                                         <font class="keywordflow">if</font> ( <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Left) )
00406                                         {
00407                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Right);
<a name="l00408"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f2">00408</a>                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00409                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c1">rotateLeft</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00410                                                 <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent-&gt;Left;
00411                                         }
00412                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f18">setNodeColor</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent) );
00413                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00414                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>-&gt;Left);
00415 
00416                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c2">rotateRight</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-&gt;Parent);
00417 
00418                                         <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#a367">w</a>);
00419                                         <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#a367">w</a>-&gt;Left);
<a name="l00420"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f3">00420</a> 
00421                                         <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>;
00422                                 }
00423                         }
00424                 }
00425                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00426                 <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>);
<a name="l00427"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f4">00427</a>         }
00428 }
00429 
00430 <font class="comment">// *********************************************************</font>
00431 <font class="comment">// Node methods</font>
00432 <font class="comment">// *********************************************************</font>
00433 
<a name="l00434"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f5">00434</a> CHeapAllocator::CNodeBegin *CHeapAllocator::splitNode (CNodeBegin *node, uint newSize)
00435 {
00436         <font class="comment">// Should be smaller than node size</font>
00437         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (newSize &lt;= <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (node));
00438 
00439         <font class="comment">// Align size</font>
00440         uint allignedSize = (newSize&amp;~(<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u17u12">Align</a>-1)) + (( (newSize&amp;(<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u17u12">Align</a>-1))==0 ) ? 0 : <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u17u12">Align</a>);
<a name="l00441"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f6">00441</a>         <font class="keywordflow">if</font> (allignedSize &lt;= <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u18u14">UserDataBlockSizeMin</a>)
00442                 allignedSize = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u18u14">UserDataBlockSizeMin</a>;
00443 
00444 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00445 <font class="preprocessor"></font>        <font class="comment">// End magic number aligned on new size</font>
00446         node-&gt;EndMagicNumber = (uint32*)((uint8*)node + newSize + <font class="keyword">sizeof</font> (CNodeBegin));
00447 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l00448"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">00448</a> <font class="preprocessor"></font>
00449         <font class="comment">// Rest is empty ?</font>
00450         <font class="keywordflow">if</font> ( <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) - allignedSize &lt; <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u18u14">UserDataBlockSizeMin</a> + <font class="keyword">sizeof</font> (CNodeBegin) + NL_HEAP_NODE_END_SIZE )
00451                 <font class="comment">// No split</font>
00452                 <font class="keywordflow">return</font> NULL;
00453 
00454         <font class="comment">// New node begin structure</font>
00455         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *newNode = (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*)((uint8*)node + <font class="keyword">sizeof</font> (CNodeBegin) + allignedSize + NL_HEAP_NODE_END_SIZE );
00456 
<a name="l00457"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f0">00457</a>         <font class="comment">// Fill the new node header</font>
00458 
00459         <font class="comment">// Size</font>
00460         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f17">setNodeSize</a> (newNode, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) - allignedSize - <font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>) - NL_HEAP_NODE_END_SIZE);
00461 
00462         <font class="comment">// Set the node free</font>
00463         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f14">setNodeFree</a> (newNode);
00464 
00465         <font class="comment">// Set the previous node pointer</font>
00466         newNode-&gt;Previous = node;
00467 
00468         <font class="comment">// Last flag</font>
00469         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f16">setNodeLast</a> (newNode, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f10">isNodeLast</a> (node));
00470 
00471 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00472 <font class="preprocessor"></font>        <font class="comment">// Begin markers</font>
00473         memset (newNode-&gt;BeginMarkers, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u3">BeginNodeMarkers</a>, CNodeBegin::MarkerSize-1);
00474         newNode-&gt;BeginMarkers[CNodeBegin::MarkerSize-1] = 0;
00475 
00476         <font class="comment">// End pointer</font>
00477         newNode-&gt;EndMagicNumber = (uint32*)((uint8*)newNode + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (newNode) + <font class="keyword">sizeof</font> (CNodeBegin));
<a name="l00478"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c17">00478</a> 
00479         <font class="comment">// End markers</font>
00480         CNodeEnd *endNode = (CNodeEnd*)((uint8*)newNode + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (newNode) + <font class="keyword">sizeof</font> (CNodeBegin));
00481         memset (endNode-&gt;EndMarkers, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u4">EndNodeMarkers</a>, CNodeEnd::MarkerSize-1);
00482         endNode-&gt;EndMarkers[CNodeEnd::MarkerSize-1] = 0;
00483 
00484         <font class="comment">// No source informations</font>
00485         newNode-&gt;File = NULL;
00486         newNode-&gt;Line = 0xffff;
00487         node-&gt;AllocateNumber = 0xffffffff;
00488         memset (newNode-&gt;Category, 0, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u2">CategoryStringLength</a>);
00489 
00490         <font class="comment">// Heap pointer</font>
00491         newNode-&gt;Heap = <font class="keyword">this</font>;
00492 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00493 <font class="preprocessor"></font>
00494         <font class="comment">// Get next node</font>
00495         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *next = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (node);
00496         <font class="keywordflow">if</font> (next)
00497         {
00498                 <font class="comment">// Set previous</font>
00499                 next-&gt;Previous = newNode;
00500 
00501                 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (next);
00502         }
00503 
00504         <font class="comment">// Should be big enough</font>
00505         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (newNode) &gt;= <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u18u14">UserDataBlockSizeMin</a>);
00506 
00507         <font class="comment">// New size of the first node</font>
00508         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f17">setNodeSize</a> (node, allignedSize);
00509 
00510         <font class="comment">// No more the last</font>
00511         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f16">setNodeLast</a> (node, <font class="keyword">false</font>);
00512 
00513         <font class="comment">// Return new node</font>
00514         <font class="keywordflow">return</font> newNode;
00515 }
00516 
00517 <font class="comment">// *********************************************************</font>
00518 
00519 <font class="keywordtype">void</font> CHeapAllocator::mergeNode (CNodeBegin *node)
00520 {
00521         <font class="comment">// Get the previous node to merge with</font>
00522         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *previous = node-&gt;Previous;
00523         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (previous) == node);
00524         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (previous);
00525         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (previous));
00526 
00527         <font class="comment">// New size</font>
00528         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f17">setNodeSize</a> (previous, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (previous) + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) + <font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>) + NL_HEAP_NODE_END_SIZE);
00529 
00530 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00531 <font class="preprocessor"></font>        <font class="comment">// Set end pointers</font>
00532         previous-&gt;EndMagicNumber = (uint32*)((uint8*)previous + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (previous) + <font class="keyword">sizeof</font> (CNodeBegin));
00533 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00534 <font class="preprocessor"></font>
00535         <font class="comment">// Get the next node to relink</font>
00536         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *next = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (node);
00537         <font class="keywordflow">if</font> (next)
00538         {
00539                 <font class="comment">// Relink</font>
00540                 next-&gt;Previous = previous;
00541 
00542                 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (next);
00543         }
<a name="l00544"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c0">00544</a> 
00545         <font class="comment">// Get the last flag</font>
00546         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f16">setNodeLast</a> (previous, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f10">isNodeLast</a> (node));
00547 
00548 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00549 <font class="preprocessor"></font>
00550         <font class="comment">// todo align</font>
00551 
00552         <font class="comment">// Clear the node informations</font>
00553         memset (((uint8*)node + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) + <font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>)), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u7">DeletedMemory</a>, NL_HEAP_NODE_END_SIZE);
00554         memset (node, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u7">DeletedMemory</a>, <font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>));
00555 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00556 <font class="preprocessor"></font>}
00557 
00558 
00559 <font class="comment">// *********************************************************</font>
00560 <font class="comment">// *********************************************************</font>
00561 
00562 <font class="comment">// Synchronized methods</font>
00563 
00564 <font class="comment">// *********************************************************</font>
00565 <font class="comment">// *********************************************************</font>
00566 
00567 
00568 <font class="keywordtype">void</font> CHeapAllocator::initEmptyBlock (CMainBlock&amp; mainBlock)
00569 {
00570         <font class="comment">// Get the node pointer</font>
00571         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *node = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (&amp;mainBlock);
00572 
00573         <font class="comment">// Allocated size remaining after alignment</font>
00574         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((uint32)node - (uint32)mainBlock.Ptr &gt;= 0);
00575         uint allocSize = mainBlock.Size - ((uint32)node - (uint32)mainBlock.Ptr);
00576 
00577         <font class="comment">// *** Fill the new node header</font>
00578 
00579         <font class="comment">// User data size</font>
00580         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f17">setNodeSize</a> (node, allocSize-<font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>)-NL_HEAP_NODE_END_SIZE);
00581 
00582         <font class="comment">// Node is free</font>
00583         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f14">setNodeFree</a> (node);
00584 
00585         <font class="comment">// Node is last</font>
00586         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f16">setNodeLast</a> (node, <font class="keyword">true</font>);
00587 
00588         <font class="comment">// No previous node</font>
00589         node-&gt;Previous = NULL;
00590 
00591         <font class="comment">// Debug info</font>
00592 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00593 <font class="preprocessor"></font>        <font class="comment">// End magic number</font>
00594         node-&gt;EndMagicNumber = (uint32*)((uint8*)node + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) + <font class="keyword">sizeof</font> (CNodeBegin));
00595 
00596         <font class="comment">// Begin markers</font>
00597         memset (node-&gt;BeginMarkers, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u3">BeginNodeMarkers</a>, CNodeBegin::MarkerSize-1);
00598         node-&gt;BeginMarkers[CNodeBegin::MarkerSize-1] = 0;
00599 
00600         <font class="comment">// End markers</font>
00601         CNodeEnd *endNode = (CNodeEnd*)node-&gt;EndMagicNumber;
00602         memset (endNode-&gt;EndMarkers, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u4">EndNodeMarkers</a>, CNodeEnd::MarkerSize-1);
00603         endNode-&gt;EndMarkers[CNodeEnd::MarkerSize-1] = 0;
00604 
00605         <font class="comment">// Unallocated memory</font>
00606         memset ((uint8*)node + <font class="keyword">sizeof</font>(<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u5">UnallocatedMemory</a>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) );
00607 
00608         <font class="comment">// No source file</font>
00609         memset (node-&gt;Category, 0, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u2">CategoryStringLength</a>);
00610         node-&gt;File = NULL;
00611         node-&gt;Line = 0xffff;
00612         node-&gt;AllocateNumber = 0xffffffff;
00613 
00614         <font class="comment">// Heap pointer</font>
00615         node-&gt;Heap = <font class="keyword">this</font>;
00616 
00617         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
00618 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00619 <font class="preprocessor"></font>}
00620 
00621 <font class="comment">// *********************************************************</font>
00622 
00623 uint CHeapAllocator::getBlockSize (<font class="keywordtype">void</font> *block)
00624 {
00625         <font class="comment">// Get the node pointer</font>
00626         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *node = (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)block - <font class="keyword">sizeof</font> (CNodeBegin));
00627 
00628         <font class="keywordflow">return</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (((<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)block - <font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>))));
00629 }
00630 
00631 <font class="comment">// *********************************************************</font>
00632 
00633 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATION_NDEBUG</font>
00634 <font class="preprocessor"></font><font class="keywordtype">void</font> *CHeapAllocator::allocate (uint size)
00635 <font class="preprocessor">#else // NL_HEAP_ALLOCATION_NDEBUG</font>
00636 <font class="preprocessor"></font><font class="keywordtype">void</font> *CHeapAllocator::allocate (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)
00637 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00638 <font class="preprocessor"></font>{
00639         <font class="comment">// Check size is valid</font>
00640         <font class="keywordflow">if</font> (size != 0)
00641         {
00642 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00643 <font class="preprocessor"></font>                <font class="comment">// If category is NULL</font>
<a name="l00644"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c8">00644</a>                 <font class="keywordflow">if</font> (category == NULL)
00645                 {
00646                         <font class="comment">// Get the current category</font>
00647                         CCategory *cat = (CCategory*)_CategoryStack.getPointer ();
00648                         <font class="keywordflow">if</font> (cat)
00649                         {
00650                                 category = cat-&gt;Name;
00651                         }
00652                         <font class="keywordflow">else</font>
00653                         {
00654                                 <font class="comment">// Not yet initialised</font>
00655                                 category = <a class="code" href="memory_2heap__allocator_8cpp.html#a3">NL_HEAP_UNKNOWN_CATEGORY</a>;
00656                         }
00657                 }
00658 
00659                 <font class="comment">// Checks ?</font>
00660                 <font class="keywordflow">if</font> (_AlwaysCheck)
00661                 {
00662                         <font class="comment">// Check heap integrity</font>
00663                         internalCheckHeap (<font class="keyword">true</font>);
00664                 }
00665 
00666                 <font class="comment">// Check breakpoints</font>
00667                 <font class="comment">/*if (_Breakpoints.find (_AllocateCount) != _Breakpoints.end())</font>
00668 <font class="comment">                {</font>
00669 <font class="comment">                        // ********</font>
00670 <font class="comment">                        // * STOP *</font>
00671 <font class="comment">                        // ********</font>
00672 <font class="comment">                        // * Breakpoints allocation</font>
00673 <font class="comment">                        // ********</font>
00674 <font class="comment">                        NL_ALLOC_STOP;</font>
00675 <font class="comment">                }*/</font>
00676 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00677 <font class="preprocessor"></font>
00678                 <font class="comment">// Small or largs block ?</font>
00679 <font class="preprocessor">#ifdef NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00680 <font class="preprocessor"></font>                <font class="keywordflow">if</font> (0)
00681 <font class="preprocessor">#else // NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00682 <font class="preprocessor"></font>                <font class="keywordflow">if</font> (size &lt;= LastSmallBlock)
00683 <font class="preprocessor">#endif// NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00684 <font class="preprocessor"></font>                {
00685                         <font class="comment">// *******************</font>
00686                         <font class="comment">// Small block</font>
00687                         <font class="comment">// *******************</font>
00688                         
00689                         enterCriticalSectionSB ();
00690 
00691                         <font class="comment">// Get pointer on the free block list</font>
00692                         CNodeBegin **freeNode = (CNodeBegin **)_FreeSmallBlocks+<a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a2">NL_SIZE_TO_SMALLBLOCK_INDEX</a> (size);
00693 
00694                         <font class="comment">// Not found ?</font>
00695                         <font class="keywordflow">if</font> (*freeNode == NULL)
00696                         {
00697                                 leaveCriticalSectionSB ();
00698 
00699                                 <font class="comment">// Size must be aligned</font>
00700                                 uint alignedSize = <a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a3">NL_ALIGN_SIZE_FOR_SMALLBLOCK</a> (size);
00701 
00702                                 <font class="comment">// Use internal allocator</font>
00703                                 CSmallBlockPool *smallBlock = (CSmallBlockPool *)<a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a4">NelAlloc</a> (*<font class="keyword">this</font>, <font class="keyword">sizeof</font>(CSmallBlockPool) + SmallBlockPoolSize * (<font class="keyword">sizeof</font>(CNodeBegin) + alignedSize + 
00704                                         NL_HEAP_NODE_END_SIZE), <a class="code" href="memory_2heap__allocator_8cpp.html#a0">NL_HEAP_SB_CATEGORY</a>);
00705 
00706                                 enterCriticalSectionSB ();
00707 
00708                                 <font class="comment">// Link this new block</font>
00709                                 smallBlock-&gt;Size = alignedSize;
00710                                 smallBlock-&gt;Next = (CSmallBlockPool*)_SmallBlockPool;
00711                                 _SmallBlockPool = smallBlock;
00712 
00713                                 <font class="comment">// Initialize the block</font>
00714                                 uint pool;
00715                                 CNodeBegin *nextNode = *freeNode;
00716                                 <font class="keywordflow">for</font> (pool=0; pool&lt;SmallBlockPoolSize; pool++)
00717                                 {
00718                                         <font class="comment">// Get the pool</font>
00719                                         CNodeBegin *node = getSmallBlock (smallBlock, pool);
00720 
00721                                         <font class="comment">// Set as free</font>
00722                                         node-&gt;SizeAndFlags = alignedSize;
00723 
00724                                         <font class="comment">// Insert in the list</font>
00725                                         setNextSmallBlock (node, nextNode);
00726                                         nextNode = node;
00727 
00728                                         <font class="comment">// Set debug informations</font>
00729 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00730 <font class="preprocessor"></font>                                        <font class="comment">// Set node free</font>
00731                                         setNodeFree (node);
00732                                         
00733                                         <font class="comment">// End magic number</font>
00734                                         node-&gt;EndMagicNumber = (uint32*)(CNodeEnd*)((uint8*)node + getNodeSize (node) + <font class="keyword">sizeof</font> (CNodeBegin));
00735 
00736                                         <font class="comment">// Begin markers</font>
00737                                         memset (node-&gt;BeginMarkers, BeginNodeMarkers, CNodeBegin::MarkerSize-1);
00738                                         node-&gt;BeginMarkers[CNodeBegin::MarkerSize-1] = 0;
00739 
00740                                         <font class="comment">// End markers</font>
00741                                         CNodeEnd *endNode = (CNodeEnd*)((uint8*)node + getNodeSize (node) + <font class="keyword">sizeof</font> (CNodeBegin));
00742                                         memset (endNode-&gt;EndMarkers, EndNodeMarkers, CNodeEnd::MarkerSize-1);
00743                                         endNode-&gt;EndMarkers[CNodeEnd::MarkerSize-1] = 0;
00744 
00745                                         <font class="comment">// Unallocated memory</font>
00746                                         memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), UnallocatedMemory, getNodeSize (node) );
<a name="l00747"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c13">00747</a> 
00748                                         <font class="comment">// No source file</font>
00749                                         memset (node-&gt;Category, 0, CategoryStringLength);
00750                                         node-&gt;File = NULL;
00751                                         node-&gt;Line = 0xffff;
00752                                         node-&gt;AllocateNumber = 0xffffffff;
00753 
<a name="l00754"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c14">00754</a>                                         <font class="comment">// Heap pointer</font>
00755                                         node-&gt;Heap = <font class="keyword">this</font>;
00756 
00757                                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
00758 
00759 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00760 <font class="preprocessor"></font>                                }
<a name="l00761"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c15">00761</a> 
00762                                 <font class="comment">// Link the new blocks</font>
00763                                 *freeNode = nextNode;
00764                         }
00765 
00766                         <font class="comment">// Check allocation as been done</font>
00767                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (*freeNode);
<a name="l00768"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c16">00768</a> 
00769                         <font class="comment">// Get a node</font>
00770                         CNodeBegin *node = *freeNode;
00771 
00772                         <font class="comment">// Checks</font>
00773                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (size &lt;= getNodeSize (node));
00774                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((NL_SIZE_TO_SMALLBLOCK_INDEX (size)) &lt; (NL_SMALLBLOCK_COUNT));
<a name="l00775"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">00775</a> 
00776                         <font class="comment">// Relink</font>
00777                         *freeNode = getNextSmallBlock (node);
00778 
00779 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG               </font>
00780 <font class="preprocessor"></font>                        <font class="comment">// Check the node CRC</font>
00781                         checkNode (node, evalMagicNumber (node));
00782 
<a name="l00783"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">00783</a>                         <font class="comment">// Set node free for checks</font>
00784                         setNodeUsed (node);
00785 
00786                         <font class="comment">// Fill category</font>
00787                         strncpy (node-&gt;Category, category, CategoryStringLength-1);
00788 
00789                         <font class="comment">// Source filename</font>
00790                         node-&gt;File = sourceFile;
00791 
00792                         <font class="comment">// Source line</font>
00793                         node-&gt;Line = line;
00794 
00795                         <font class="comment">// Allocate count</font>
00796                         node-&gt;AllocateNumber = _AllocateCount++;
00797 
00798                         <font class="comment">// End magic number aligned on new size</font>
00799                         node-&gt;EndMagicNumber = (uint32*)((uint8*)node + size + <font class="keyword">sizeof</font> (CNodeBegin));
00800 
00801                         <font class="comment">// Uninitialised memory</font>
00802                         memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), UninitializedMemory, (uint32)(node-&gt;EndMagicNumber) - ( (uint32)node + <font class="keyword">sizeof</font>(CNodeBegin) ) );
00803 
00804                         <font class="comment">// Crc node</font>
00805                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
00806 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00807 <font class="preprocessor"></font>
00808                         leaveCriticalSectionSB ();
00809 
00810                         <font class="comment">// Return the user pointer</font>
00811                         <font class="keywordflow">return</font> (<font class="keywordtype">void</font>*)((uint)node + <font class="keyword">sizeof</font> (CNodeBegin));
<a name="l00812"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a8">00812</a>                 }
00813                 <font class="keywordflow">else</font>
00814                 {
00815                         <font class="comment">// *******************</font>
00816                         <font class="comment">// Large block</font>
00817                         <font class="comment">// *******************</font>
00818 
00819                         <font class="comment">// Check size</font>
00820                         <font class="keywordflow">if</font> ( (size &amp; ~CNodeBegin::SizeMask) != 0)
00821                         {
00822                                 <font class="comment">// ********</font>
00823                                 <font class="comment">// * STOP *</font>
00824                                 <font class="comment">// ********</font>
00825                                 <font class="comment">// * Attempt to allocate more than 1 Go</font>
00826                                 <font class="comment">// ********</font>
00827                                 NL_ALLOC_STOP
00828 
00829                                 <font class="comment">// Select outofmemory mode</font>
00830                                 <font class="keywordflow">if</font> (_OutOfMemoryMode == ReturnNull)
00831                                         <font class="keywordflow">return</font> NULL;
00832                                 <font class="keywordflow">else</font>
00833                                         <font class="keywordflow">throw</font> 0;
00834                         }
00835 
00836                         enterCriticalSectionLB ();
00837 
00838                         <font class="comment">// Find a free node</font>
00839                         CHeapAllocator::CFreeNode *freeNode = CHeapAllocator::find (size);
00840 
00841                         <font class="comment">// The node</font>
00842                         CNodeBegin *node;
00843 
00844                         <font class="comment">// Node not found ?</font>
00845                         <font class="keywordflow">if</font> (freeNode == NULL)
<a name="l00846"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a11">00846</a>                         {
00847                                 <font class="comment">// Block allocation mode</font>
00848                                 <font class="keywordflow">if</font> ((_BlockAllocationMode == DontGrow) &amp;&amp; (_MainBlockList != NULL))
00849                                 {
00850                                         <font class="comment">// Select outofmemory mode</font>
00851                                         <font class="keywordflow">if</font> (_OutOfMemoryMode == ReturnNull)
00852                                                 <font class="keywordflow">return</font> NULL;
00853                                         <font class="keywordflow">else</font>
00854                                                 <font class="keywordflow">throw</font> 0;
00855                                 }
00856 
<a name="l00857"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a12">00857</a>                                 <font class="comment">// The node</font>
00858                                 uint8 *buffer;
00859 
00860                                 <font class="comment">// Alloc size</font>
00861                                 uint allocSize;
00862 
00863                                 <font class="comment">// Aligned size</font>
<a name="l00864"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a9">00864</a>                                 uint allignedSize = (size&amp;~(Align-1)) + (( (size&amp;(Align-1))==0 ) ? 0 : Align);
00865                                 <font class="keywordflow">if</font> (allignedSize &lt; BlockDataSizeMin)
00866                                         allignedSize = BlockDataSizeMin;
00867 
00868                                 <font class="comment">// Does the node bigger than mainNodeSize ?</font>
00869                                 <font class="keywordflow">if</font> (allignedSize &gt; (_MainBlockSize-<font class="keyword">sizeof</font> (CNodeBegin)-NL_HEAP_NODE_END_SIZE))
00870                                         <font class="comment">// Allocate a specific block</font>
00871                                         allocSize = allignedSize + <font class="keyword">sizeof</font> (CNodeBegin) + NL_HEAP_NODE_END_SIZE;
00872                                 <font class="keywordflow">else</font>
00873                                         <font class="comment">// Allocate a new block</font>
00874                                         allocSize = _MainBlockSize;
<a name="l00875"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a10">00875</a> 
00876                                 <font class="comment">// Allocate the buffer</font>
00877                                 buffer = allocateBlock (allocSize+Align);
00878 
00879                                 <font class="comment">// Add the buffer</font>
00880                                 CMainBlock *mainBlock = (CMainBlock*)allocateBlock (<font class="keyword">sizeof</font>(CMainBlock)); 
00881                                 mainBlock-&gt;Size = allocSize+Align;
00882                                 mainBlock-&gt;Ptr = buffer;
<a name="l00883"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a21">00883</a>                                 mainBlock-&gt;Next = _MainBlockList;
00884                                 _MainBlockList = mainBlock;
00885 
00886                                 <font class="comment">// Init the new block</font>
00887                                 initEmptyBlock (*mainBlock);
00888 
00889                                 <font class="comment">// Get the first node</font>
<a name="l00890"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a6">00890</a>                                 node = getFirstNode (mainBlock);
00891                         }
00892                         <font class="keywordflow">else</font>
00893                         {
00894                                 <font class="comment">// Get the node</font>
00895                                 node = getNode (freeNode);
00896 
00897                                 <font class="comment">// Remove the node from free blocks and get the removed block</font>
00898                                 erase (freeNode);
00899                         }
<a name="l00900"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">00900</a> 
00901 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00902 <font class="preprocessor"></font>                        <font class="comment">// Check the node CRC</font>
00903                         checkNode (node, evalMagicNumber (node));
00904 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00905 <font class="preprocessor"></font>
00906                         <font class="comment">// Split the node</font>
<a name="l00907"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f26">00907</a>                         CNodeBegin *rest = splitNode (node, size);
00908 
00909                         <font class="comment">// Fill informations for the first part of the node</font>
00910 
00911                         <font class="comment">// Clear free flag</font>
00912                         setNodeUsed (node);
00913 
<a name="l00914"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f27">00914</a> <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00915 <font class="preprocessor"></font>                        <font class="comment">// Fill category</font>
00916                         strncpy (node-&gt;Category, category, CategoryStringLength-1);
00917 
00918                         <font class="comment">// Source filename</font>
00919                         node-&gt;File = sourceFile;
00920 
00921                         <font class="comment">// Source line</font>
00922                         node-&gt;Line = line;
00923 
00924                         <font class="comment">// Allocate count</font>
00925                         node-&gt;AllocateNumber = _AllocateCount++;
00926 
00927                         <font class="comment">// Crc node</font>
00928                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
00929 
00930                         <font class="comment">// Uninitialised memory</font>
00931                         memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), UninitializedMemory, (uint32)(node-&gt;EndMagicNumber) - ( (uint32)node + <font class="keyword">sizeof</font>(CNodeBegin) ) );
00932 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00933 <font class="preprocessor"></font>
00934                         <font class="comment">// Node has been splited ?</font>
00935                         <font class="keywordflow">if</font> (rest)
<a name="l00936"></a><a class="code" href="memory_2heap__allocator_8cpp.html#a0">00936</a>                         {
<a name="l00937"></a><a class="code" href="memory_2heap__allocator_8cpp.html#a1">00937</a>                                 <font class="comment">// Fill informations for the second part of the node</font>
<a name="l00938"></a><a class="code" href="memory_2heap__allocator_8cpp.html#a2">00938</a> 
<a name="l00939"></a><a class="code" href="memory_2heap__allocator_8cpp.html#a3">00939</a>                                 <font class="comment">// Get the freeNode</font>
00940                                 freeNode = getFreeNode (rest);
00941 
00942                                 <font class="comment">// Insert the free node</font>
00943                                 insert (freeNode);
00944 
00945                                 <font class="comment">// Crc node</font>
00946                                 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (rest);
00947                         }
00948 
00949                         <font class="comment">// Check the node size</font>
00950                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ( size &lt;= getNodeSize (node) );
00951                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ( std::max ((uint)BlockDataSizeMin, size + (uint)Align) + <font class="keyword">sizeof</font> (CNodeBegin) + <font class="keyword">sizeof</font> (CNodeEnd) + <font class="keyword">sizeof</font> (CNodeBegin) + <font class="keyword">sizeof</font> (CNodeEnd) + BlockDataSizeMin &gt;= getNodeSize (node) );
00952 
<a name="l00953"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a0">00953</a>                         <font class="comment">// Check pointer alignment</font>
00954                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (((uint32)node&amp;(Align-1)) == 0);
00955                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (((uint32)((<font class="keywordtype">char</font>*)node + <font class="keyword">sizeof</font>(CNodeBegin))&amp;(Align-1)) == 0);
00956 
00957                         <font class="comment">// Check size</font>
00958                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((uint32)node-&gt;EndMagicNumber &lt;= (uint32)((uint8*)node+<font class="keyword">sizeof</font>(CNodeBegin)+getNodeSize (node) ));
00959                         <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((uint32)node-&gt;EndMagicNumber &gt; (uint32)(((uint8*)node+<font class="keyword">sizeof</font>(CNodeBegin)+getNodeSize (node) ) - BlockDataSizeMin - BlockDataSizeMin - <font class="keyword">sizeof</font>(CNodeBegin) - <font class="keyword">sizeof</font>(CNodeEnd)));
00960 
00961                         leaveCriticalSectionLB ();
00962 
00963                         <font class="comment">// Return the user pointer</font>
00964                         <font class="keywordflow">return</font> (<font class="keywordtype">void</font>*)((uint)node + <font class="keyword">sizeof</font> (CNodeBegin));
00965                 }
00966         }
00967         <font class="keywordflow">else</font>
00968         {
00969                 <font class="comment">// ********</font>
00970                 <font class="comment">// * STOP *</font>
00971                 <font class="comment">// ********</font>
00972                 <font class="comment">// * Attempt to allocate 0 bytes</font>
00973                 <font class="comment">// ********</font>
00974                 NL_ALLOC_STOP;
00975                 <font class="keywordflow">return</font> NULL;
00976         }
00977 }
00978 
00979 <font class="comment">// *********************************************************</font>
00980 
00981 <font class="keywordtype">void</font> CHeapAllocator::free (<font class="keywordtype">void</font> *ptr)
00982 {
00983         <font class="comment">// Delete a null pointer ?</font>
00984         <font class="keywordflow">if</font> (ptr == NULL)
00985         {
00986                 <font class="comment">// ********</font>
00987                 <font class="comment">// * STOP *</font>
00988                 <font class="comment">// ********</font>
00989                 <font class="comment">// * Attempt to delete a NULL pointer</font>
00990                 <font class="comment">// ********</font>
00991 <font class="preprocessor">#ifdef NL_HEAP_STOP_NULL_FREE</font>
00992 <font class="preprocessor"></font>                NL_ALLOC_STOP;
00993 <font class="preprocessor">#endif // NL_HEAP_STOP_NULL_FREE</font>
00994 <font class="preprocessor"></font>        }
00995         <font class="keywordflow">else</font>
00996         {
00997 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00998 <font class="preprocessor"></font>                <font class="comment">// Checks ?</font>
00999                 <font class="keywordflow">if</font> (_AlwaysCheck)
01000                 {
01001                         <font class="comment">// Check heap integrity</font>
01002                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c10">internalCheckHeap</a> (<font class="keyword">true</font>);
01003                 }
01004 
01005                 <font class="comment">// Get the node pointer</font>
01006                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *node = (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin));
01007 
01008                 <font class="comment">// Check the node CRC</font>
01009                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c13">enterCriticalSectionSB</a> ();
01010                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c15">enterCriticalSectionLB</a> ();
<a name="l01011"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a1">01011</a>                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c9">checkNode</a> (node, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (node));
01012                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c16">leaveCriticalSectionLB</a> ();
01013                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c14">leaveCriticalSectionSB</a> ();
01014 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01015 <font class="preprocessor"></font>
01016                 <font class="comment">// Large or small block ?</font>
01017 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATION_NDEBUG</font>
01018 <font class="preprocessor"></font>                uint size = (((<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin))))-&gt;SizeAndFlags;
<a name="l01019"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c3">01019</a> <font class="preprocessor">#else // NL_HEAP_ALLOCATION_NDEBUG</font>
01020 <font class="preprocessor"></font>                uint size = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (((<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)ptr - <font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>))));
01021 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01022 <font class="preprocessor"></font>                <font class="keywordflow">if</font> (size &lt;= <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s7">LastSmallBlock</a>)
01023                 {
01024                         <font class="comment">// *******************</font>
01025                         <font class="comment">// Small block</font>
01026                         <font class="comment">// *******************</font>
01027 
01028                         <font class="comment">// Check the node has not been deleted</font>
01029                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (node))
01030                         {
01031                                 <font class="comment">// ********</font>
01032                                 <font class="comment">// * STOP *</font>
01033                                 <font class="comment">// ********</font>
01034                                 <font class="comment">// * Attempt to delete a pointer already deleted</font>
01035                                 <font class="comment">// ********</font>
01036                                 <font class="comment">// * (*node):   the already deleted node</font>
01037                                 <font class="comment">// ********</font>
01038                                 NL_ALLOC_STOP;
01039                         }
01040                         <font class="keywordflow">else</font>
01041                         {
01042                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c13">enterCriticalSectionSB</a> ();
01043 
01044 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01045 <font class="preprocessor"></font>                                <font class="comment">// Uninitialised memory</font>
01046                                 memset ((uint8*)node + <font class="keyword">sizeof</font>(<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u7">DeletedMemory</a>, size );
01047 
01048                                 <font class="comment">// Set end pointers</font>
01049                                 node-&gt;EndMagicNumber = (uint32*)((uint8*)node + size + <font class="keyword">sizeof</font> (CNodeBegin));
01050 
01051                                 <font class="comment">// Mark has free</font>
01052                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f14">setNodeFree</a> (node);
01053 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01054 <font class="preprocessor"></font>
01055                                 <font class="comment">// Add in the free list</font>
01056                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> **freeNode = (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> **)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o11">_FreeSmallBlocks</a>+<a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a2">NL_SIZE_TO_SMALLBLOCK_INDEX</a> (size);
01057                                 ((<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin)))-&gt;Previous = *freeNode;
01058                                 *freeNode = ((<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin)));
01059 
01060                                 <font class="comment">// Update smallblock crc</font>
01061                                 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
01062 
01063                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c14">leaveCriticalSectionSB</a> ();
01064                         }
01065                 }
01066                 <font class="keywordflow">else</font>
01067                 {
01068 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATION_NDEBUG</font>
01069 <font class="preprocessor"></font>                        <font class="comment">// Get the real size</font>
01070                         size = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (((<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)ptr - <font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>))));
01071 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01072 <font class="preprocessor"></font>
01073                         <font class="comment">// Get the node pointer</font>
01074                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *node = (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin));
01075 
01076                         <font class="comment">// Check the node has not been deleted</font>
01077                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (node))
01078                         {
01079                                 <font class="comment">// ********</font>
01080                                 <font class="comment">// * STOP *</font>
01081                                 <font class="comment">// ********</font>
01082                                 <font class="comment">// * Attempt to delete a pointer already deleted</font>
01083                                 <font class="comment">// ********</font>
01084                                 <font class="comment">// * (*node):   the already deleted node</font>
01085                                 <font class="comment">// ********</font>
01086                                 NL_ALLOC_STOP;
01087                         }
01088                         <font class="keywordflow">else</font>
01089                         {
01090                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c15">enterCriticalSectionLB</a> ();
01091 
01092 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01093 <font class="preprocessor"></font>                                <font class="comment">// Uninitialised memory</font>
01094                                 memset ((uint8*)node + <font class="keyword">sizeof</font>(<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u7">DeletedMemory</a>, size );
01095 
01096                                 <font class="comment">// Set end pointers</font>
01097                                 node-&gt;EndMagicNumber = (uint32*)((uint8*)node + size + <font class="keyword">sizeof</font> (CNodeBegin));
01098 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01099 <font class="preprocessor"></font>
01100                                 <font class="comment">// Mark has free</font>
01101                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f14">setNodeFree</a> (node);
01102 
01103                                 <font class="comment">// *******************</font>
01104                                 <font class="comment">// Large block</font>
01105                                 <font class="comment">// *******************</font>
01106 
01107                                 <font class="comment">// A free node</font>
01108                                 CHeapAllocator::CFreeNode *freeNode = NULL;
01109 
01110                                 <font class="comment">// Previous node</font>
01111                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *previous = node-&gt;Previous;
01112                                 <font class="keywordflow">if</font> (previous)
01113                                 {
01114 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01115 <font class="preprocessor"></font>                                        <font class="comment">// Check the previous node</font>
01116                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c9">checkNode</a> (previous, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (previous));
01117 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01118 <font class="preprocessor"></font>
01119                                         <font class="comment">// Is it free ?</font>
01120                                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (previous))
01121                                         {
01122                                                 <font class="comment">// Merge the two nodes</font>
01123                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f23">mergeNode</a> (node);
01124 
01125                                                 <font class="comment">// Get its free node</font>
01126                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c4">erase</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f3">getFreeNode</a> (previous));
01127 
01128                                                 <font class="comment">// Curent node</font>
01129                                                 node = previous;
01130                                         }
01131                                 }
01132 
01133                                 <font class="comment">// Mark has free</font>
01134                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f14">setNodeFree</a> (node);
01135 
01136                                 <font class="comment">// Next node</font>
01137                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *next = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (node);
01138                                 <font class="keywordflow">if</font> (next)
01139                                 {
01140 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01141 <font class="preprocessor"></font>                                        <font class="comment">// Check the next node</font>
<a name="l01142"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c4">01142</a>                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c9">checkNode</a> (next, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (next));
01143 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01144 <font class="preprocessor"></font>
01145                                         <font class="comment">// Is it free ?</font>
01146                                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (next))
01147                                         {
01148                                                 <font class="comment">// Free the new one</font>
01149                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c4">erase</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f3">getFreeNode</a> (next));
01150 
01151                                                 <font class="comment">// Merge the two nodes</font>
01152                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f23">mergeNode</a> (next);
01153                                         }
01154                                 }
01155 
01156                                 <font class="comment">// Insert it into the tree</font>
01157                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c3">insert</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f3">getFreeNode</a> (node));
01158 
01159                                 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
01160                                 
01161                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c16">leaveCriticalSectionLB</a> ();
01162                         }
01163                 }
01164         }
01165 }
01166 
01167 <font class="comment">// *********************************************************</font>
01168 <font class="comment">// Statistics</font>
01169 <font class="comment">// *********************************************************</font>
01170 
01171 uint CHeapAllocator::getAllocatedMemory ()<font class="keyword"> const</font>
01172 <font class="keyword"></font>{
01173         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01174 
01175         <font class="comment">// Sum allocated memory</font>
01176         uint memory = 0;
01177 
01178         <font class="comment">// For each small block</font>
01179         CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01180         <font class="keywordflow">while</font> (currentSB)
01181         {
01182                 <font class="comment">// For each node in this small block pool</font>
01183                 uint block;
01184                 <font class="keywordflow">for</font> (block=0; block&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>; block++)
01185                 {
01186                         <font class="comment">// Get the node</font>
01187                         <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01188 
01189                         <font class="comment">// Node allocated ?</font>
01190                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01191                                 memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u1">ReleaseHeaderSize</a>;
01192                 }
01193 
01194                 <font class="comment">// Next block</font>
01195                 currentSB = currentSB-&gt;Next;
01196         }
01197 
01198         <font class="comment">// For each main block</font>
01199         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01200         <font class="keywordflow">while</font> (currentBlock)
01201         {
01202                 <font class="comment">// Get the first node</font>
01203                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01204                 <font class="keywordflow">while</font> (current)
01205                 {
01206 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01207 <font class="preprocessor"></font>                        <font class="comment">// Check node</font>
01208                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c9">checkNode</a> (current, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (current));
01209 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01210 <font class="preprocessor"></font>
01211                         <font class="comment">// Node allocated ? Don't sum small blocks..</font>
01212                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current) &amp;&amp; (strcmp (current-&gt;Category, <a class="code" href="memory_2heap__allocator_8cpp.html#a0">NL_HEAP_SB_CATEGORY</a>) != 0))
01213                                 memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u1">ReleaseHeaderSize</a>;
01214 
01215                         <font class="comment">// Next node</font>
01216                         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01217                 }
01218 
01219                 <font class="comment">// Next block</font>
01220                 currentBlock = currentBlock-&gt;Next;
01221         }
01222 
01223         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01224 
01225         <font class="comment">// Return memory used</font>
01226         <font class="keywordflow">return</font> memory;
01227 }
01228 
01229 <font class="comment">// *********************************************************</font>
01230 
01231 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01232 <font class="preprocessor"></font>uint CHeapAllocator::debugGetAllocatedMemoryByCategory (<font class="keyword">const</font> <font class="keywordtype">char</font>* category)<font class="keyword"> const</font>
01233 <font class="keyword"></font>{
01234         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01235 
01236         <font class="comment">// Sum allocated memory</font>
01237         uint memory = 0;
01238 
01239         <font class="comment">// For each small block</font>
01240         CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01241         <font class="keywordflow">while</font> (currentSB)
01242         {
01243                 <font class="comment">// For each node in this small block pool</font>
01244                 uint block;
01245                 <font class="keywordflow">for</font> (block=0; block&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>; block++)
01246                 {
01247                         <font class="comment">// Get the node</font>
01248                         <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01249 
01250                         <font class="comment">// Node allocated ?</font>
01251                         <font class="keywordflow">if</font> ((<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current)) &amp;&amp; (strcmp (current-&gt;Category, category)==0))
01252                                 memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
01253 
01254                         memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
01255                 }
01256 
01257                 <font class="comment">// Next block</font>
01258                 currentSB = currentSB-&gt;Next;
01259         }
01260 
01261         <font class="comment">// For each main block</font>
01262         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01263         <font class="keywordflow">while</font> (currentBlock)
01264         {
01265                 <font class="comment">// Get the first node</font>
01266                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01267                 <font class="keywordflow">while</font> (current)
01268                 {
01269                         <font class="comment">// Node allocated ?</font>
01270                         <font class="keywordflow">if</font> ((<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current)) &amp;&amp; (strcmp (current-&gt;Category, category)==0))
01271                                 memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
01272 
01273                         <font class="comment">// Next node</font>
01274                         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01275                 }
01276 
01277                 <font class="comment">// Next block</font>
01278                 currentBlock = currentBlock-&gt;Next;
01279         }
01280 
01281         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01282 
01283         <font class="comment">// Return memory used</font>
01284         <font class="keywordflow">return</font> memory;
01285 }
01286 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01287 <font class="preprocessor"></font>
01288 <font class="comment">// *********************************************************</font>
01289 
01290 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01291 <font class="preprocessor"></font>uint CHeapAllocator::debugGetDebugInfoSize ()<font class="keyword"> const</font>
01292 <font class="keyword"></font>{
01293         <font class="comment">// Return memory used</font>
01294         <font class="keywordflow">return</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a23">debugGetSBDebugInfoSize</a> () + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a24">debugGetLBDebugInfoSize</a> ();
01295 }
01296 
01297 uint CHeapAllocator::debugGetLBDebugInfoSize ()<font class="keyword"> const</font>
01298 <font class="keyword"></font>{
01299         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01300 
01301         <font class="comment">// Sum memory used by debug header</font>
01302         uint memory = 0;
01303 
01304         <font class="comment">// For each main block</font>
01305         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01306         <font class="keywordflow">while</font> (currentBlock)
01307         {
01308                 <font class="comment">// Get the first node</font>
01309                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01310                 <font class="keywordflow">while</font> (current)
01311                 {
01312                         <font class="comment">// Node allocated ?</font>
01313                         memory  += <font class="keyword">sizeof</font>(CNodeBegin) - <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u1">ReleaseHeaderSize</a> + <font class="keyword">sizeof</font>(CNodeEnd);
01314 
01315                         <font class="comment">// Next node</font>
01316                         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01317                 }
01318 
01319                 <font class="comment">// Next block</font>
01320                 currentBlock = currentBlock-&gt;Next;
01321         }
01322 
01323         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
<a name="l01324"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c6">01324</a> 
01325         <font class="comment">// Return memory used</font>
01326         <font class="keywordflow">return</font> memory;
01327 }
01328 
01329 uint CHeapAllocator::debugGetSBDebugInfoSize ()<font class="keyword"> const</font>
01330 <font class="keyword"></font>{
01331         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01332 
01333         <font class="comment">// Sum memory used by debug header</font>
01334         uint memory = 0;
01335 
01336         <font class="comment">// For each small blocks</font>
01337         CSmallBlockPool *pool = (CSmallBlockPool*)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01338         <font class="keywordflow">while</font> (pool)
01339         {
01340                 memory  += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a> * (<font class="keyword">sizeof</font>(CNodeBegin) - <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u1">ReleaseHeaderSize</a> + <font class="keyword">sizeof</font>(CNodeEnd));
01341 
01342                 <font class="comment">// Next pool</font>
01343                 pool = pool-&gt;Next;
01344         }
01345 
01346         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01347 
01348         <font class="comment">// Return memory used</font>
01349         <font class="keywordflow">return</font> memory;
01350 }
01351 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01352 <font class="preprocessor"></font>
01353 <font class="comment">// *********************************************************</font>
01354 
01355 <font class="keywordtype">void</font> <a class="code" href="namespaceNLMEMORY.html#a3">fprintf_int</a> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)
01356 {
01357         
01358 }
01359 
01360 <font class="comment">// *********************************************************</font>
01361 
01362 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01363 <font class="preprocessor"></font>
01364 <font class="keyword">class </font>CCategoryMap
01365 {
01366 <font class="keyword">public</font>:
01367         <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">CCategoryMap</a> (<font class="keyword">const</font> <font class="keywordtype">char</font> *name, <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">CCategoryMap</a> *next)
01368         {
01369                 <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m0">Name</a> = name;
01370                 <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m1">BlockCount</a> = 0;
01371                 <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m2">Size</a> = 0;
01372                 <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m3">Min</a> = 0xffffffff;
01373                 <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m4">Max</a> = 0;
01374                 <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m5">Next</a> = next;
01375         }
01376 
01377         <font class="keyword">static</font> <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">CCategoryMap</a> *<a class="code" href="classNLMEMORY_1_1CCategoryMap.html#d0">find</a> (<a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">CCategoryMap</a> *cat, <font class="keyword">const</font> <font class="keywordtype">char</font> *name)
01378         {
01379                 <font class="keywordflow">while</font> (cat)
01380                 {
01381                         <font class="keywordflow">if</font> (strcmp (name, cat-&gt;Name) == 0)
01382                                 <font class="keywordflow">break</font>;
01383                         cat = cat-&gt;Next;
01384                 }
01385                 <font class="keywordflow">return</font> cat;
01386         }
01387 
01388         <font class="keyword">static</font> <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">CCategoryMap</a> *<a class="code" href="classNLMEMORY_1_1CCategoryMap.html#d1">insert</a> (<font class="keyword">const</font> <font class="keywordtype">char</font> *name, <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">CCategoryMap</a> *next)
01389         {
01390                 <font class="keywordflow">return</font> <font class="keyword">new</font> <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">CCategoryMap</a> (name, next);
01391         }
01392 
01393         <font class="keyword">const</font> <font class="keywordtype">char</font>              *<a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m0">Name</a>;
01394         uint                    <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m1">BlockCount</a>;
01395         uint                    <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m2">Size</a>;
01396         uint                    <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m3">Min</a>;
01397         uint                    <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m4">Max</a>;
01398         <a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">CCategoryMap</a>    *<a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m5">Next</a>;
01399 };
01400 
01401 <font class="keywordtype">bool</font> CHeapAllocator::debugStatisticsReport (<font class="keyword">const</font> <font class="keywordtype">char</font>* stateFile, <font class="keywordtype">bool</font> memoryMap)
01402 {
01403         <font class="comment">// Status</font>
01404         <font class="keywordtype">bool</font> status = <font class="keyword">false</font>;
01405 
01406         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a34">debugPushCategoryString</a> (<a class="code" href="memory_2heap__allocator_8cpp.html#a2">NL_HEAP_MEM_DEBUG_CATEGORY</a>);
01407 
01408         <font class="comment">// Open files</font>
<a name="l01409"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f23">01409</a>         FILE *<a class="code" href="cf__lexical_8cpp.html#a95">file</a> = fopen (stateFile, <font class="stringliteral">"wt"</font>);
01410 
01411         <font class="comment">// List of category</font>
01412         CCategoryMap *catMap = NULL;
01413 
01414         <font class="comment">// Both OK</font>
01415         <font class="keywordflow">if</font> (file)
01416         {
01417                 <font class="comment">// **************************</font>
01418 
01419                 <font class="comment">// For each small block</font>
01420                 uint smallBlockCount = 0;
01421                 uint largeBlockCount = 0;
01422                 CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01423                 <font class="keywordflow">while</font> (currentSB)
01424                 {
01425                         <font class="comment">// For each node in this small block pool</font>
01426                         uint block;
01427                         <font class="keywordflow">for</font> (block=0; block&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>; block++)
01428                         {
01429                                 <font class="comment">// Get the node</font>
01430                                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01431 
01432                                 <font class="comment">// Node allocated ?</font>
01433                                 <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01434                                 {
01435                                         <font class="comment">// Find the node</font>
01436                                         CCategoryMap *cat = CCategoryMap::find (catMap, (<font class="keyword">const</font> <font class="keywordtype">char</font>*)current-&gt;Category);
01437 
01438                                         <font class="comment">// Found ?</font>
01439                                         <font class="keywordflow">if</font> (cat == NULL)
01440                                         {
01441                                                 catMap = CCategoryMap::insert (current-&gt;Category, catMap);
01442                                                 cat = catMap;
01443                                         }
01444                                         uint size = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u1">ReleaseHeaderSize</a>;
01445                                         cat-&gt;BlockCount++;
01446                                         cat-&gt;Size += size;
01447                                         <font class="keywordflow">if</font> (size &lt; cat-&gt;Min)
01448                                                 cat-&gt;Min = size;
01449                                         <font class="keywordflow">if</font> (size &gt; cat-&gt;Max)
01450                                                 cat-&gt;Max = size;
01451                                 }
01452 
01453                                 <font class="comment">// Next node</font>
01454                                 smallBlockCount++;
01455                         }
01456 
01457                         <font class="comment">// Next block</font>
<a name="l01458"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c7">01458</a>                         currentSB = currentSB-&gt;Next;
01459                 }
01460 
01461                 <font class="comment">// For each main block</font>
01462                 CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01463                 <font class="keywordflow">while</font> (currentBlock)
01464                 {
01465                         <font class="comment">// Get the first node</font>
01466                         <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01467                         <font class="keywordflow">while</font> (current)
01468                         {
01469                                 <font class="comment">// Node is used ?</font>
01470                                 <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01471                                 {
01472                                         <font class="comment">// Find the node</font>
01473                                         CCategoryMap *cat = CCategoryMap::find (catMap, (<font class="keyword">const</font> <font class="keywordtype">char</font>*)current-&gt;Category);
01474 
01475                                         <font class="comment">// Found ?</font>
01476                                         <font class="keywordflow">if</font> (cat == NULL)
01477                                         {
01478                                                 catMap = CCategoryMap::insert (current-&gt;Category, catMap);
01479                                                 cat = catMap;
01480                                         }
01481                                         uint size = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u1">ReleaseHeaderSize</a>;
01482                                         cat-&gt;BlockCount++;
01483                                         cat-&gt;Size += size;
01484                                         <font class="keywordflow">if</font> (size &lt; cat-&gt;Min)
01485                                                 cat-&gt;Min = size;
01486                                         <font class="keywordflow">if</font> (size &gt; cat-&gt;Max)
01487                                                 cat-&gt;Max = size;
01488                                 }
01489 
01490                                 <font class="comment">// Next node</font>
01491                                 current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01492                                 largeBlockCount++;
01493                         }
01494 
01495                         <font class="comment">// Next block</font>
01496                         currentBlock = currentBlock-&gt;Next;
01497                 }
01498 
01499                 <font class="comment">// Write the heap info file</font>
01500                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"HEAP STATISTICS\n"</font>);
01501                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"HEAP, TOTAL MEMORY USED, ALLOCATED MEMORY, FREE MEMORY, FRAGMENTATION RATIO, MAIN BLOCK SIZE, MAIN BLOCK COUNT\n"</font>);
01502 
01503                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%s, %d, %d, %d, %f%%, %d, %d\n"</font>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o9">_Name</a>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a16">getTotalMemoryUsed</a> (),
01504                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a14">getAllocatedMemory</a> (), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a15">getFreeMemory</a> (), 100.f*<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a19">getFragmentationRatio</a> (), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a6">getMainBlockSize</a> (), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a8">getMainBlockCount</a> ());
01505 
01506                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\nHEAP BLOCKS\n"</font>);
01507                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"SMALL BLOCK MEMORY, SMALL BLOCK COUNT, LARGE BLOCK COUNT\n"</font>);
01508 
01509                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%d, %d, %d\n"</font>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a17">getSmallBlockMemory</a> (), smallBlockCount, largeBlockCount);
01510 
01511                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\nHEAP DEBUG INFOS\n"</font>);
01512                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"SB DEBUG INFO, LB DEBUG INFO, TOTAL DEBUG INFO\n"</font>);
<a name="l01513"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#d0">01513</a> 
01514                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%d, %d, %d\n"</font>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a23">debugGetSBDebugInfoSize</a> (), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a24">debugGetLBDebugInfoSize</a> (), <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a22">debugGetDebugInfoSize</a> ());
01515 
01516                 <font class="comment">// **************************</font>
01517 
01518                 <font class="comment">// Write the system heap info file</font>
01519                 uint systemMemory = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#d1">getAllocatedSystemMemory</a> ();
01520                 uint nelSystemMemory = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a18">getAllocatedSystemMemoryByAllocator</a> ();
01521 
01522                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\nSYSTEM HEAP STATISTICS\n"</font>);
01523                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"TOTAL ALLOCATED MEMORY, NEL ALLOCATED MEMORY, OTHER ALLOCATED MEMORY\n"</font>);
01524                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%d, %d, %d\n"</font>, systemMemory, nelSystemMemory, systemMemory-nelSystemMemory);
01525 
<a name="l01526"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a32">01526</a>                 <font class="comment">// Write the category map file</font>
01527                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\n\nCATEGORY STATISTICS\n"</font>);
01528                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"CATEGORY, BLOCK COUNT, MEMORY ALLOCATED, MIN BLOCK SIZE, MAX BLOCK SIZE, AVERAGE BLOCK SIZE, SB COUNT 8, SB COUNT 16, SB COUNT 24, SB COUNT 32, SB COUNT 40, SB COUNT 48, SB COUNT 56, SB COUNT 64, SB COUNT 72, SB COUNT 80, SB COUNT 88, SB COUNT 96, SB COUNT 104, SB COUNT 112, SB COUNT 120, SB COUNT 128\n"</font>);
01529 
01530                 CCategoryMap *cat = catMap;
01531                 <font class="keywordflow">while</font> (cat)
01532                 {
01533                         CCategoryMap *next = cat-&gt;Next;
01534 
01535                         <font class="comment">// Number of small blocks</font>
01536                         uint smallB[NL_SMALLBLOCK_COUNT];
01537 
01538                         <font class="comment">// Clean</font>
01539                         uint smallBlock;
01540                         <font class="keywordflow">for</font> (smallBlock=0; smallBlock&lt;NL_SMALLBLOCK_COUNT; smallBlock++)
01541                         {
01542                                 smallB[smallBlock] = 0;
01543                         }
01544                         
01545                         <font class="comment">// Scan small block for this category</font>
01546                         currentSB = (CSmallBlockPool *)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01547                         <font class="keywordflow">while</font> (currentSB)
01548                         {
01549                                 <font class="comment">// For each node in this small block pool</font>
01550                                 uint block;
01551                                 <font class="keywordflow">for</font> (block=0; block&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>; block++)
01552                                 {
01553                                         <font class="comment">// Get the node</font>
01554                                         <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01555 
01556                                         <font class="comment">// Node allocated ?</font>
01557                                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01558                                         {
01559                                                 <font class="comment">// Good node ?</font>
01560                                                 <font class="keywordflow">if</font> (strcmp (current-&gt;Category, cat-&gt;Name) == 0)
01561                                                 {
01562                                                         <font class="comment">// Get the small block index</font>
01563                                                         uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> = <a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a2">NL_SIZE_TO_SMALLBLOCK_INDEX</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current));
01564 
01565                                                         <font class="comment">// One more node</font>
01566                                                         smallB[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++;
01567                                                 }
01568                                         }
01569                                 }
01570 
01571                                 <font class="comment">// Next block</font>
01572                                 currentSB = currentSB-&gt;Next;
01573                         }
01574 
01575                         <font class="comment">// Average</font>
01576                         uint average = cat-&gt;Size / cat-&gt;BlockCount;
01577 
01578                         <font class="comment">// Print the line</font>
01579                         fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%s, %d, %d, %d, %d, %d"</font>, cat-&gt;Name, cat-&gt;BlockCount, cat-&gt;Size, 
01580                                 cat-&gt;Min, cat-&gt;Max, average);
01581 
01582                         <font class="comment">// Print small blocks</font>
01583                         <font class="keywordflow">for</font> (smallBlock=0; smallBlock&lt;NL_SMALLBLOCK_COUNT; smallBlock++)
01584                         {
01585                                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">", %d"</font>, smallB[smallBlock]);
01586                         }
01587 
01588                         fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n"</font>);
01589 
01590                         <font class="keyword">delete</font> cat;
01591                         cat = next;
01592                 }
01593 
01594                 <font class="comment">// **************************</font>
01595 
01596                 <font class="comment">// Write the small block statistics</font>
01597                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\n\nSMALL BLOCK STATISTICS\n"</font>);
01598                 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"SIZE, BLOCK COUNT, BLOCK FREE, BLOCK USED, TOTAL MEMORY USED\n"</font>);
01599 
01600                 <font class="comment">// Number of small blocks</font>
01601                 uint count[NL_SMALLBLOCK_COUNT];
01602                 uint <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a>[NL_SMALLBLOCK_COUNT];
01603 
01604                 uint smallBlock;
01605                 <font class="keywordflow">for</font> (smallBlock=0; smallBlock&lt;NL_SMALLBLOCK_COUNT; smallBlock++)
01606                 {
01607                         count[smallBlock] = 0;
01608                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a>[smallBlock] = 0;
01609                 }
01610 
01611                 <font class="comment">// For each small block</font>
01612                 currentSB = (CSmallBlockPool *)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01613                 <font class="keywordflow">while</font> (currentSB)
01614                 {
01615                         <font class="comment">// For each node in this small block pool</font>
01616                         uint block;
01617                         <font class="keywordflow">for</font> (block=0; block&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>; block++)
01618                         {
01619                                 <font class="comment">// Get the node</font>
01620                                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01621 
01622                                 <font class="comment">// Get the small block index</font>
01623                                 uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> = <a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a2">NL_SIZE_TO_SMALLBLOCK_INDEX</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current));
01624 
01625                                 <font class="comment">// Add a block</font>
01626                                 count[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++;
01627 
01628                                 <font class="comment">// Node allocated ?</font>
01629                                 <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (current))
01630                                 {
01631                                         <font class="comment">// Add a free block</font>
01632                                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++;
01633                                 }
01634 
01635                                 <font class="comment">// Next node</font>
01636                                 current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01637                         }
01638 
01639                         <font class="comment">// Next block</font>
01640                         currentSB = currentSB-&gt;Next;
01641                 }
01642 
01643                 <font class="comment">// Print stats</font>
01644                 <font class="keywordflow">for</font> (smallBlock=0; smallBlock&lt;NL_SMALLBLOCK_COUNT; smallBlock++)
01645                 {
01646                         uint size = (smallBlock+1)*<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s5">SmallBlockGranularity</a>;
01647                         fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>,<font class="stringliteral">"%d, %d, %d, %d, %d\n"</font>,size, count[smallBlock], <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a>[smallBlock], 
01648                                 count[smallBlock]-<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a>[smallBlock], count[smallBlock]*(<font class="keyword">sizeof</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>) + size + NL_HEAP_NODE_END_SIZE));
01649                 }
01650                 
01651                 <font class="comment">// **************************</font>
01652 
01653                 <font class="comment">// Write the memory map file</font>
01654                 <font class="keywordflow">if</font> (memoryMap)
01655                 {
01656                         fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\n\nHEAP LARGE BLOCK DUMP\n"</font>);
01657                         fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"ADDRESS, SIZE, CATEGORY, HEAP, STATE, SOURCE, LINE\n"</font>);
01658 
01659                         <font class="comment">// For each main block</font>
01660                         currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01661                         <font class="keywordflow">while</font> (currentBlock)
01662                         {
01663                                 <font class="comment">// Get the first node</font>
01664                                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01665                                 <font class="keywordflow">while</font> (current)
01666                                 {
01667                                         <font class="comment">// Write the entry</font>
01668                                         fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"0x%08x, %d, %s, %s, %s, %s, %d\n"</font>, (uint)current + <font class="keyword">sizeof</font>(<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>),
01669                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current), current-&gt;Category, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o9">_Name</a>, 
01670                                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (current)?<font class="stringliteral">"free"</font>:<font class="stringliteral">"used"</font>, current-&gt;File, current-&gt;Line);
01671 
01672                                         <font class="comment">// Next node</font>
01673                                         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01674                                 }
01675 
01676                                 <font class="comment">// Next block</font>
01677                                 currentBlock = currentBlock-&gt;Next;
01678                         }
01679                 }
01680 
01681                 <font class="comment">// File created successfuly</font>
01682                 status = <font class="keyword">true</font>;
01683         }
01684 
01685         <font class="comment">// Close</font>
01686         <font class="keywordflow">if</font> (file)
01687                 fclose (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>);
01688 
01689         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a35">debugPopCategoryString</a> ();
01690 
01691         <font class="keywordflow">return</font> status;
01692 }
01693 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01694 <font class="preprocessor"></font>
01695 <font class="comment">// *********************************************************</font>
01696 
01697 uint CHeapAllocator::getFreeMemory ()<font class="keyword"> const</font>
01698 <font class="keyword"></font>{
01699         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01700 
01701         <font class="comment">// Sum free memory</font>
01702         uint memory = 0;
01703 
01704         <font class="comment">// For each small block</font>
01705         CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01706         <font class="keywordflow">while</font> (currentSB)
01707         {
01708                 <font class="comment">// For each node in this small block pool</font>
01709                 uint block;
01710                 <font class="keywordflow">for</font> (block=0; block&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>; block++)
01711                 {
01712                         <font class="comment">// Get the node</font>
01713                         <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01714 
01715                         <font class="comment">// Node allocated ?</font>
01716                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (current))
01717                                 memory  += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u1">ReleaseHeaderSize</a>;
01718 
01719                         <font class="comment">// Next node</font>
01720                         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01721                 }
01722 
01723                 <font class="comment">// Next block</font>
01724                 currentSB = currentSB-&gt;Next;
01725         }
01726 
01727         <font class="comment">// For each main block</font>
01728         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01729         <font class="keywordflow">while</font> (currentBlock)
01730         {
01731                 <font class="comment">// Get the first node</font>
01732                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01733                 <font class="keywordflow">while</font> (current)
01734                 {
01735 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01736 <font class="preprocessor"></font>                        <font class="comment">// Check node</font>
01737                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c9">checkNode</a> (current, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (current));
01738 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01739 <font class="preprocessor"></font>
01740                         <font class="comment">// Node allocated ?</font>
01741                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f8">isNodeFree</a> (current))
01742                                 memory  += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u1">ReleaseHeaderSize</a>;
01743 
01744                         <font class="comment">// Next node</font>
01745                         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01746                 }
01747 
01748                 <font class="comment">// Next block</font>
01749                 currentBlock = currentBlock-&gt;Next;
01750         }
01751 
01752         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01753 
01754         <font class="comment">// Return memory used</font>
01755         <font class="keywordflow">return</font> memory;
01756 }
01757 
01758 <font class="comment">// *********************************************************</font>
01759 
01760 uint CHeapAllocator::getTotalMemoryUsed ()<font class="keyword"> const</font>
01761 <font class="keyword"></font>{
01762         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01763 
01764         <font class="comment">// Sum total memory</font>
01765         uint memory = 0;
01766 
01767         <font class="comment">// For each main block</font>
01768         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01769         <font class="keywordflow">while</font> (currentBlock)
01770         {
01771                 <font class="comment">// Get block size</font>
01772                 memory += currentBlock-&gt;<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CMainBlock.html#m0">Size</a>;
01773 
01774                 <font class="comment">// Sum the arrays</font>
01775                 memory += <font class="keyword">sizeof</font> (CMainBlock);
01776 
01777                 <font class="comment">// Next block</font>
01778                 currentBlock = currentBlock-&gt;Next;
01779         }
01780 
01781         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01782 
01783         <font class="comment">// Return the memory</font>
01784         <font class="keywordflow">return</font> memory;
01785 }
01786 
01787 <font class="comment">// *********************************************************</font>
01788 
01789 uint CHeapAllocator::getSmallBlockMemory ()<font class="keyword"> const</font>
01790 <font class="keyword"></font>{
01791         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01792 
01793         <font class="comment">// Sum total memory</font>
01794         uint memory = 0;
01795 
01796         <font class="comment">// For each small block</font>
01797         CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01798         <font class="keywordflow">while</font> (currentSB)
01799         {
01800                 <font class="comment">// Get block size</font>
01801                 memory += <font class="keyword">sizeof</font>(CSmallBlockPool) + <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a> * (<font class="keyword">sizeof</font>(CNodeBegin) + currentSB-&gt;Size + 
01802                                         NL_HEAP_NODE_END_SIZE);
01803 
01804                 <font class="comment">// Next block</font>
01805                 currentSB = currentSB-&gt;Next;
01806         }
01807 
01808         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01809 
01810         <font class="comment">// Return the memory</font>
01811         <font class="keywordflow">return</font> memory;
01812 }
01813 
01814 <font class="comment">// *********************************************************</font>
01815 
01816 <font class="keywordtype">float</font> CHeapAllocator::getFragmentationRatio ()<font class="keyword"> const</font>
01817 <font class="keyword"></font>{
01818         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01819 
01820         <font class="comment">// Sum free and used node</font>
01821         <font class="keywordtype">float</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a> = 0;
01822         <font class="keywordtype">float</font> used = 0;
01823 
01824         <font class="comment">// For each main block</font>
01825         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01826         <font class="keywordflow">while</font> (currentBlock)
01827         {
01828                 <font class="comment">// Get the first node</font>
01829                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01830                 <font class="keywordflow">while</font> (current)
01831                 {
01832                         <font class="comment">// Node allocated ?</font>
01833                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01834                                 used++;
01835                         <font class="keywordflow">else</font>
01836                                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a>++;
01837 
01838                         <font class="comment">// Next node</font>
01839                         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01840                 }
01841 
01842                 <font class="comment">// Next block</font>
01843                 currentBlock = currentBlock-&gt;Next;
01844         }
01845 
01846         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01847 
01848         <font class="comment">// Return the memory</font>
01849         <font class="keywordflow">if</font> (used != 0)
01850                 <font class="keywordflow">return</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a> / used;
01851         <font class="keywordflow">else</font>
01852                 <font class="keywordflow">return</font> 0;
01853 }
01854 
01855 <font class="comment">// *********************************************************</font>
01856 
01857 <font class="keywordtype">void</font>    CHeapAllocator::freeAll ()
01858 {
01859         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01860 
01861         <font class="comment">// Sum free memory</font>
01862         uint memory = 0;
01863 
01864         <font class="comment">// Clear the free tree</font>
01865         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
01866 
01867         <font class="comment">// For each main block</font>
01868         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01869         <font class="keywordflow">while</font> (currentBlock)
01870         {
<a name="l01871"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">01871</a>                 <font class="comment">// Reinit this block</font>
01872                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c7">initEmptyBlock</a> (*currentBlock);
01873 
01874                 <font class="comment">// Get first block</font>
01875                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *node = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01876 
01877                 <font class="comment">// Insert the free node</font>
01878                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c3">insert</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f3">getFreeNode</a> (node));
01879 
01880                 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
01881 
01882                 <font class="comment">// Next block</font>
01883                 currentBlock = currentBlock-&gt;Next;
01884         }
01885 
01886         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01887 }
01888 
01889 <font class="comment">// *********************************************************</font>
01890 
01891 <font class="keywordtype">void</font>    CHeapAllocator::releaseMemory ()
01892 {
01893         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01894 
01895         <font class="comment">// Clear the free tree</font>
01896         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = &amp;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMEMORY_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
01897 
01898         <font class="comment">// For each main block</font>
01899         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01900         <font class="keywordflow">while</font> (currentBlock)
01901         {
01902                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a31">freeBlock</a> (currentBlock-&gt;Ptr);
01903 
01904                 <font class="comment">// Next block</font>
01905                 CMainBlock *toDelete = currentBlock;
01906                 currentBlock = toDelete-&gt;Next;
01907                 ::free (toDelete);
01908         }
01909 
01910         <font class="comment">// Erase block node</font>
01911         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a> = NULL;
01912 
01913         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01914 }
01915 
01916 <font class="comment">// *********************************************************</font>
01917 
01918 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01919 <font class="preprocessor"></font>
01920 <font class="keyword">class </font>CLeak
01921 {
01922 <font class="keyword">public</font>:
01923         
01924         <a class="code" href="classNLMEMORY_1_1CLeak.html#a0">CLeak</a> (<font class="keyword">const</font> <font class="keywordtype">char</font> *name, <a class="code" href="classNLMEMORY_1_1CLeak.html#a0">CLeak</a> *next)
01925         {
01926                 <a class="code" href="classNLMEMORY_1_1CLeak.html#m2">Name</a> = <font class="keyword">new</font> <font class="keywordtype">char</font>[strlen (name)+1];
01927                 strcpy (<a class="code" href="classNLMEMORY_1_1CLeak.html#m2">Name</a>, name);
01928                 <a class="code" href="classNLMEMORY_1_1CLeak.html#m0">Count</a> = 0;
01929                 <a class="code" href="classNLMEMORY_1_1CLeak.html#m1">Memory</a> = 0;
01930                 <a class="code" href="classNLMEMORY_1_1CLeak.html#m3">Next</a> = next;
01931         }
01932 
01933         <a class="code" href="classNLMEMORY_1_1CLeak.html#a1">~CLeak</a> ()
01934         {
01935                 <font class="keyword">delete</font> [] <a class="code" href="classNLMEMORY_1_1CLeak.html#m2">Name</a>;
01936                 <font class="keywordflow">if</font> (Next)
01937                         <font class="keyword">delete</font> <a class="code" href="classNLMEMORY_1_1CLeak.html#m3">Next</a>;
01938         }
01939 
01940         <font class="keyword">static</font> <a class="code" href="classNLMEMORY_1_1CLeak.html#a0">CLeak</a> *<a class="code" href="classNLMEMORY_1_1CLeak.html#d0">find</a> (<a class="code" href="classNLMEMORY_1_1CLeak.html#a0">CLeak</a> *cat, <font class="keyword">const</font> <font class="keywordtype">char</font> *name)
01941         {
01942                 <font class="keywordflow">while</font> (cat)
01943                 {
01944                         <font class="keywordflow">if</font> (strcmp (name, cat-&gt;Name) == 0)
01945                                 <font class="keywordflow">break</font>;
01946                         cat = cat-&gt;Next;
01947                 }
01948                 <font class="keywordflow">return</font> cat;
01949         }
01950 
01951         <font class="keyword">static</font> <a class="code" href="classNLMEMORY_1_1CLeak.html#a0">CLeak</a> *<a class="code" href="classNLMEMORY_1_1CLeak.html#d1">insert</a> (<font class="keyword">const</font> <font class="keywordtype">char</font> *name, <a class="code" href="classNLMEMORY_1_1CLeak.html#a0">CLeak</a> *next)
01952         {
01953                 <font class="keywordflow">return</font> <font class="keyword">new</font> <a class="code" href="classNLMEMORY_1_1CLeak.html#a0">CLeak</a> (name, next);
01954         }
01955 
01956         uint                    <a class="code" href="classNLMEMORY_1_1CLeak.html#m0">Count</a>;
01957         uint                    <a class="code" href="classNLMEMORY_1_1CLeak.html#m1">Memory</a>;
01958         <font class="keywordtype">char</font>                    *<a class="code" href="classNLMEMORY_1_1CLeak.html#m2">Name</a>;
01959         <a class="code" href="classNLMEMORY_1_1CLeak.html#a0">CLeak</a>                   *<a class="code" href="classNLMEMORY_1_1CLeak.html#m3">Next</a>;
01960 };
01961 
01962 <font class="comment">// typedef std::map&lt;std::string, CLeak&gt; TLinkMap;</font>
01963 
01964 <font class="keywordtype">void</font> CHeapAllocator::debugReportMemoryLeak ()
01965 {
01966         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a34">debugPushCategoryString</a> (<a class="code" href="memory_2heap__allocator_8cpp.html#a2">NL_HEAP_MEM_DEBUG_CATEGORY</a>);
01967 
01968         <font class="comment">// Sum allocated memory</font>
01969         uint memory = 0;
01970 
01971         <font class="comment">// Leak map</font>
01972         CLeak *leakMap = NULL;
01973 
01974         <font class="comment">// Header</font>
01975         <font class="keywordtype">char</font> report[2048];
01976         sprintf (report, <font class="stringliteral">"Report Memory leak for allocator \"%s\"\n"</font>, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o9">_Name</a>);
01977         <a class="code" href="namespaceNLMEMORY.html#a2">CHeapAllocatorOutputError</a> (report);
01978 
01979         <font class="comment">// For each small block</font>
01980         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01981         <font class="keywordflow">while</font> (currentBlock)
01982         {
01983                 <font class="comment">// Get the first node</font>
01984                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01985                 <font class="keywordflow">while</font> (current)
01986                 {
01987                         <font class="comment">// Check node</font>
01988                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c9">checkNode</a> (current, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (current));
01989 
01990                         <font class="comment">// Node allocated ?</font>
01991                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current) &amp;&amp; ( (current-&gt;Category == NULL) || (current-&gt;Category[0] != <font class="charliteral">'_'</font>)) )
01992                         {
01993                                 <font class="comment">// Make a report</font>
01994                                 sprintf (report, <font class="stringliteral">"%s(%d)\t: \"%s\""</font>, current-&gt;File, current-&gt;Line, current-&gt;Category);
01995 
01996                                 <font class="comment">// Look for this leak</font>
01997                                 CLeak *ite = CLeak::find (leakMap, report);
01998 
01999                                 <font class="comment">// Not found ?</font>
02000                                 <font class="keywordflow">if</font> (ite == NULL)
02001                                 {
02002                                         ite = CLeak::insert (report, leakMap);
02003                                         leakMap = ite;
02004                                         ite-&gt;Count = 0;
02005                                         ite-&gt;Memory = 0;
02006                                 }
02007 
02008                                 <font class="comment">// One more leak</font>
02009                                 ite-&gt;Count++;
02010                                 ite-&gt;Memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
02011 
02012                                 memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
02013                         }
02014 
02015                         <font class="comment">// Next node</font>
02016                         current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
02017                 }
02018 
02019                 <font class="comment">// Next block</font>
02020                 currentBlock = currentBlock-&gt;Next;
02021         }
02022 
02023         <font class="comment">// For each small block</font>
02024         CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
02025         <font class="keywordflow">while</font> (currentSB)
02026         {
02027                 <font class="comment">// For each node in this small block pool</font>
02028                 uint block;
02029                 <font class="keywordflow">for</font> (block=0; block&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>; block++)
02030                 {
02031                         <font class="comment">// Get the node</font>
02032                         <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
02033                         <font class="comment">// Check node</font>
02034                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c9">checkNode</a> (current, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (current));
02035 
02036                         <font class="comment">// Node allocated ?</font>
02037                         <font class="keywordflow">if</font> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current) &amp;&amp; ( (current-&gt;Category == NULL) || (current-&gt;Category[0] != <font class="charliteral">'_'</font>)) )
02038                         {
02039                                 <font class="comment">// Make a report</font>
02040                                 sprintf (report, <font class="stringliteral">"%s(%d)\t: \"%s\""</font>,    current-&gt;File, current-&gt;Line, current-&gt;Category);
02041 
02042                                 <font class="comment">// Look for this leak</font>
02043                                 CLeak *ite = CLeak::find (leakMap, report);
02044 
02045                                 <font class="comment">// Not found ?</font>
02046                                 <font class="keywordflow">if</font> (ite == NULL)
02047                                 {
02048                                         ite = CLeak::insert (report, leakMap);
02049                                         leakMap = ite;
02050                                         ite-&gt;Count = 0;
02051                                         ite-&gt;Memory = 0;
02052                                 }
02053 
02054                                 <font class="comment">// One more leak</font>
02055                                 ite-&gt;Count++;
02056                                 ite-&gt;Memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
02057 
02058                                 memory += <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
02059                         }
02060                 }
<a name="l02061"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a14">02061</a> 
02062                 <font class="comment">// Next block</font>
02063                 currentSB = currentSB-&gt;Next;
02064         }
02065 
02066         <font class="comment">// Look for this leak</font>
02067         CLeak *ite = leakMap;
02068         <font class="keywordflow">while</font> (ite)
02069         {
02070                 <font class="comment">// Make a report</font>
02071                 sprintf (report, <font class="stringliteral">"%s,\tLeak count : %d,\tMemory allocated : %d\n"</font>, ite-&gt;Name, ite-&gt;Count, ite-&gt;Memory);
02072 
02073                 <font class="comment">// Report on stderr</font>
02074                 <a class="code" href="namespaceNLMEMORY.html#a2">CHeapAllocatorOutputError</a> (report);
02075 
02076                 ite = ite-&gt;Next;
02077         }
02078 
02079         <font class="comment">// Make a report</font>
02080         <font class="keywordflow">if</font> (memory)
02081         {
02082                 sprintf (report, <font class="stringliteral">"%d byte(s) found\n"</font>, memory);
02083         }
02084         <font class="keywordflow">else</font>
02085         {
02086                 sprintf (report, <font class="stringliteral">"No memory leak\n"</font>);
02087         }
02088         <a class="code" href="namespaceNLMEMORY.html#a2">CHeapAllocatorOutputError</a> (report);
02089 
02090         <font class="comment">// Delete list</font>
02091         <font class="keywordflow">if</font> (leakMap)
02092                 <font class="keyword">delete</font> leakMap;
02093 
02094         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a35">debugPopCategoryString</a> ();
02095 }
02096 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
02097 <font class="preprocessor"></font>
02098 <font class="comment">// *********************************************************</font>
02099 
02100 <font class="keywordtype">bool</font> CHeapAllocator::checkHeap (<font class="keywordtype">bool</font> stopOnError)<font class="keyword"> const</font>
02101 <font class="keyword"></font>{
02102         <font class="keywordtype">bool</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c10">internalCheckHeap</a> (stopOnError);
02103 
02104         <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
02105 }
02106 
02107 <font class="comment">// *********************************************************</font>
02108 
02109 uint8 *CHeapAllocator::allocateBlock (uint size)
02110 {
02111 <font class="preprocessor">#undef malloc</font>
02112 <font class="preprocessor"></font>        <font class="keywordflow">return</font> (uint8*)::malloc (size);
02113 }
02114 
02115 <font class="comment">// *********************************************************</font>
02116 
02117 <font class="keywordtype">void</font> CHeapAllocator::freeBlock (uint8 *block)
02118 {
02119         ::free (block);
02120 }
02121 
<a name="l02122"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a25">02122</a> <font class="comment">// *********************************************************</font>
02123 
02124 <font class="keywordtype">bool</font> CHeapAllocator::internalCheckHeap (<font class="keywordtype">bool</font> stopOnError)<font class="keyword"> const</font>
02125 <font class="keyword"></font>{
02126         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
02127 
02128         <font class="comment">// For each small blocks</font>
02129         CSmallBlockPool *pool = (CSmallBlockPool*)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
02130         <font class="keywordflow">while</font> (pool)
02131         {
02132                 <font class="comment">// For each small block</font>
02133                 uint smallBlock;
02134                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>      *previous = NULL;
02135                 <font class="keywordflow">for</font> (smallBlock=0; smallBlock&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>; smallBlock++)
02136                 {
02137                         <font class="comment">// Get the small block</font>
02138                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>      *node = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (pool, smallBlock);
02139                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a>      *next = (smallBlock+1&lt;<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#s11s8">SmallBlockPoolSize</a>) ? <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f25">getSmallBlock</a> (pool, smallBlock+1) : NULL;
02140 
02141                         <font class="comment">// Check node</font>
02142                         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c17">checkNodeSB</a> (pool, previous, node, next, stopOnError);
02143 
02144                         previous = node;
02145                 }
02146 
02147                 <font class="comment">// Next pool</font>
02148                 pool = pool-&gt;Next;
02149         }
02150         
02151         <font class="comment">// For each main block</font>
02152         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
02153         <font class="keywordflow">while</font> (currentBlock)
02154         {
02155                 <font class="comment">// Get the nodes</font>
02156                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *previous = NULL;
02157                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *current = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
02158                 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (current);       <font class="comment">// Should have at least one block in the main block</font>
02159                 <font class="keyword">const</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#l0">CNodeBegin</a> *next;
02160                 
02161                 <font class="comment">// For each node</font>
02162                 <font class="keywordflow">while</font> (current)
02163                 {
02164                         <font class="comment">// Get next</font>
02165                         next = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
02166 
02167                         <font class="comment">// Return Error ?</font>
02168                         <font class="keywordflow">if</font> (!<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c0">checkNodeLB</a> (currentBlock, previous, current, next, stopOnError))
02169                                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
02170 
02171                         <font class="comment">// Next</font>
02172                         previous = current;
02173                         current = next;
02174                 }
02175 
02176                 <font class="comment">// Next block</font>
02177                 currentBlock = currentBlock-&gt;Next;
02178         }
02179 
02180         <font class="comment">// Check free tree</font>
<a name="l02181"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a22">02181</a>         <font class="keywordflow">if</font> (!<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c8">checkFreeNode</a> (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>, stopOnError, <font class="keyword">true</font>))
02182                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
02183 
02184         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
02185 
02186         <font class="comment">// Ok, no problem</font>
<a name="l02187"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a24">02187</a>         <font class="keywordflow">return</font> <font class="keyword">true</font>;
02188 }
02189 
02190 <font class="comment">// *********************************************************</font>
02191 
02192 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
02193 <font class="preprocessor"></font><font class="keywordtype">void</font> CHeapAllocator::debugAlwaysCheckMemory (<font class="keywordtype">bool</font> alwaysCheck)
02194 {
02195         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o4">_AlwaysCheck</a> = alwaysCheck;
02196 }
02197 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
02198 <font class="preprocessor"></font>
02199 <font class="comment">// *********************************************************</font>
02200 
02201 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
02202 <font class="preprocessor"></font><font class="keywordtype">bool</font> CHeapAllocator::debugIsAlwaysCheckMemory (<font class="keywordtype">bool</font> alwaysCheck)<font class="keyword"> const</font>
02203 <font class="keyword"></font>{
02204         <font class="keywordflow">return</font> <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o4">_AlwaysCheck</a>;
02205 }
02206 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
02207 <font class="preprocessor"></font>
02208 <font class="comment">// *********************************************************</font>
02209 
02210 <font class="keywordtype">void</font>    CHeapAllocator::setName (<font class="keyword">const</font> <font class="keywordtype">char</font>* name)
02211 {
02212         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
02213 
02214         strncpy (<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o9">_Name</a>, name, <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#u15u8">NameLength</a>-1);
02215 
02216         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
02217 }
02218 
<a name="l02219"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a23">02219</a> <font class="comment">// *********************************************************</font>
02220 <font class="comment">// Category control</font>
02221 <font class="comment">// *********************************************************</font>
02222 
02223 <font class="keywordtype">void</font> CHeapAllocator::debugPushCategoryString (<font class="keyword">const</font> <font class="keywordtype">char</font> *str)
02224 {
02225         <font class="comment">// Get the category stack pointer</font>
02226         CCategory *last = (CCategory*)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o14">_CategoryStack</a>.getPointer ();
02227 
02228         <font class="comment">// New category node</font>
02229         CCategory *_new = (CCategory *)<a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a4">NelAlloc</a> (*<font class="keyword">this</font>, <font class="keyword">sizeof</font>(CCategory), <a class="code" href="memory_2heap__allocator_8cpp.html#a1">NL_HEAP_CATEGORY_BLOCK_CATEGORY</a>);
02230         _new-&gt;Name = str;
02231         _new-&gt;Next = last;
02232 
02233         <font class="comment">/* Push it, no need to be thread safe here, because we use thread specifc storage */</font>
02234         <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o14">_CategoryStack</a>.setPointer (_new);
02235 }
02236 
02237 <font class="comment">// *********************************************************</font>
02238 
02239 <font class="keywordtype">void</font> CHeapAllocator::debugPopCategoryString ()
02240 {
02241         <font class="comment">// Get the category stack pointer</font>
02242         CCategory *last = (CCategory*)<a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o14">_CategoryStack</a>.getPointer ();
02243         <font class="comment">// nlassertex (last, ("(CHeapAllocator::debugPopCategoryString ()) Pop category wihtout Push"));</font>
02244         <font class="keywordflow">if</font> (last)
02245         {
02246                 CCategory *next = last-&gt;Next;
02247 
02248                 <font class="comment">// Free last node, no need to be thread safe here, because we use thread specifc storage</font>
02249                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a2">free</a> (last);
02250 
02251                 <font class="comment">/* Push it, no need to be thread safe here, because we use thread specifc storage */</font>
02252                 <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o14">_CategoryStack</a>.setPointer (next);
02253         }
<a name="l02254"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html">02254</a> }
02255 
02256 <font class="comment">// *********************************************************</font>
<a name="l02257"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#a0">02257</a> 
02258 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
02259 <font class="preprocessor"></font>
02260 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
02261 <font class="preprocessor"></font><font class="preprocessor">#pragma optimize( "", off )</font>
02262 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font>
02263 <font class="preprocessor"></font>
02264 <font class="keywordtype">void</font> CHeapAllocator::checkNode (<font class="keyword">const</font> CNodeBegin *node, uint32 crc)<font class="keyword"> const</font>
02265 <font class="keyword"></font>{
02266         <font class="comment">// Check the bottom CRC of the node </font>
<a name="l02267"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#d0">02267</a>         <font class="keywordflow">if</font> (crc != *(node-&gt;EndMagicNumber))
02268         {
02269                 <font class="comment">// ********</font>
02270                 <font class="comment">// * STOP *</font>
02271                 <font class="comment">// ********</font>
02272                 <font class="comment">// * The bottom CRC32 of the current node is wrong. Use checkMemory() to debug the heap.</font>
02273                 <font class="comment">// ********</font>
02274                 <font class="comment">// * (*node) Check for more informations</font>
02275                 <font class="comment">// ********</font>
02276                 NL_ALLOC_STOP;
02277         }
<a name="l02278"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#d1">02278</a> 
02279         <font class="comment">// Check the node is hold by this heap</font>
02280         <font class="keywordflow">if</font> (node-&gt;Heap != <font class="keyword">this</font>)
02281         {
02282                 <font class="comment">// ********</font>
<a name="l02283"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m0">02283</a>                 <font class="comment">// * STOP *</font>
<a name="l02284"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m1">02284</a>                 <font class="comment">// ********</font>
<a name="l02285"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m2">02285</a>                 <font class="comment">// * This node is not hold by this heap. It has been allocated with another heap.</font>
<a name="l02286"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m3">02286</a>                 <font class="comment">// ********</font>
<a name="l02287"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m4">02287</a>                 <font class="comment">// * (*node) Check for more informations</font>
<a name="l02288"></a><a class="code" href="classNLMEMORY_1_1CCategoryMap.html#m5">02288</a>                 <font class="comment">// ********</font>
02289                 NL_ALLOC_STOP;
02290         }
<a name="l02291"></a><a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#a26">02291</a> }
02292 
02293 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
02294 <font class="preprocessor"></font><font class="preprocessor">#pragma optimize( "", on )</font>
02295 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font>
02296 <font class="preprocessor"></font>
02297 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
02298 <font class="preprocessor"></font>
02299 <font class="comment">// *********************************************************</font>
02300 
02301 uint CHeapAllocator::getAllocatedSystemMemory ()
02302 {
02303         uint systemMemory = 0;
02304 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
02305 <font class="preprocessor"></font>        <font class="comment">// Get system memory informations</font>
02306         HANDLE hHeap[100];
02307         DWORD heapCount = GetProcessHeaps (100, hHeap);
02308 
02309         uint heap;
02310         <font class="keywordflow">for</font> (heap = 0; heap &lt; heapCount; heap++)
02311         {
02312                 PROCESS_HEAP_ENTRY entry;
02313                 entry.lpData = NULL;
02314                 <font class="keywordflow">while</font> (HeapWalk (hHeap[heap], &amp;entry))
02315                 {
02316                         <font class="keywordflow">if</font> (entry.wFlags &amp; PROCESS_HEAP_ENTRY_BUSY)
02317                         {
02318                                 systemMemory += entry.cbData + entry.cbOverhead;
02319                         }
02320                 }
02321         }
02322 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
02323 <font class="preprocessor"></font>        <font class="keywordflow">return</font> systemMemory;
02324 }
02325 
02326 <font class="comment">// *********************************************************</font>
02327 
02328 <font class="keyword">class </font>CPointerEntry
02329 {
02330 <font class="keyword">public</font>:
02331         <a class="code" href="classNLMEMORY_1_1CPointerEntry.html#a0">CPointerEntry</a> (<font class="keywordtype">void</font>     *<a class="code" href="driver__opengl__extension__def_8h.html#a362">pointer</a>, <a class="code" href="classNLMEMORY_1_1CPointerEntry.html#a0">CPointerEntry</a> *entry)
02332         {
02333                 <a class="code" href="classNLMEMORY_1_1CPointerEntry.html#m0">Pointer</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a362">pointer</a>;
02334                 <a class="code" href="classNLMEMORY_1_1CPointerEntry.html#m1">Next</a> = entry;
02335         }
02336         <font class="keyword">static</font> <a class="code" href="classNLMEMORY_1_1CPointerEntry.html#a0">CPointerEntry</a> *<a class="code" href="classNLMEMORY_1_1CPointerEntry.html#d0">find</a> (<a class="code" href="classNLMEMORY_1_1CPointerEntry.html#a0">CPointerEntry</a> *cat, <font class="keywordtype">void</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a362">pointer</a>)
02337         {
02338                 <font class="keywordflow">while</font> (cat)
02339                 {
02340                         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a362">pointer</a> == cat-&gt;Pointer)
02341                                 <font class="keywordflow">break</font>;
02342                         cat = cat-&gt;Next;
02343                 }
02344                 <font class="keywordflow">return</font> cat;
02345         }
02346         <font class="keywordtype">void</font>                    *<a class="code" href="classNLMEMORY_1_1CPointerEntry.html#m0">Pointer</a>;
02347         <a class="code" href="classNLMEMORY_1_1CPointerEntry.html#a0">CPointerEntry</a>   *<a class="code" href="classNLMEMORY_1_1CPointerEntry.html#m1">Next</a>;
02348 };
02349 
02350 uint CHeapAllocator::getAllocatedSystemMemoryByAllocator ()
02351 {
02352         uint nelSystemMemory = 0;
02353 
02354         <font class="comment">// Build a set of allocated system memory pointers</font>
02355         CPointerEntry *entries = NULL;
02356 
02357         <font class="comment">// For each main block</font>
02358         CMainBlock *currentBlock = <a class="code" href="classNLMEMORY_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
02359         <font class="keywordflow">while</font> (currentBlock)
02360         {
02361                 <font class="comment">// Save pointers</font>
02362                 entries = <font class="keyword">new</font> CPointerEntry ((<font class="keywordtype">void</font>*)currentBlock, entries);
02363                 entries = <font class="keyword">new</font> CPointerEntry ((<font class="keywordtype">void</font>*)currentBlock-&gt;Ptr, entries);
02364 
02365                 <font class="comment">// Next block</font>
02366                 currentBlock = currentBlock-&gt;Next;
02367         }
02368 
02369 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
02370 <font class="preprocessor"></font>        <font class="comment">// Get system memory informations</font>
02371         HANDLE hHeap[100];
02372         DWORD heapCount = GetProcessHeaps (100, hHeap);
02373 
02374         uint heap;
02375         <font class="keywordflow">for</font> (heap = 0; heap &lt; heapCount; heap++)
02376         {
02377                 PROCESS_HEAP_ENTRY entry;
02378                 entry.lpData = NULL;
02379                 <font class="keywordflow">while</font> (HeapWalk (hHeap[heap], &amp;entry))
02380                 {
02381                         <font class="keywordflow">if</font> (entry.wFlags &amp; PROCESS_HEAP_ENTRY_BUSY)
02382                         {
02383                                 <font class="comment">// This pointer is already used ?</font>
02384                                 <font class="keywordflow">if</font> ( CPointerEntry::find (entries, (<font class="keywordtype">void</font>*)((<font class="keywordtype">char</font>*)entry.lpData)) || 
02385                                         CPointerEntry::find (entries, (<font class="keywordtype">void</font>*)((<font class="keywordtype">char</font>*)entry.lpData+32) ) )
02386                                         nelSystemMemory += entry.cbData + entry.cbOverhead;
02387                         }
02388                 }
02389         }
02390 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
02391 <font class="preprocessor"></font>
02392         <font class="keywordflow">return</font> nelSystemMemory;
02393 }
02394 
02395 <font class="comment">// *********************************************************</font>
02396 
02397 } <font class="comment">// NLMEMORY</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>