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
|
<!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="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>heap_allocator.cpp</h1><a href="misc_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="stdmisc_8h.html">stdmisc.h</a>"</font>
00033
00034 <font class="preprocessor">#include "<a class="code" href="include_2nel_2misc_2heap__allocator_8h.html">nel/misc/heap_allocator.h</a>"</font>
00035 <font class="preprocessor">#include "<a class="code" href="debug_8h.html">nel/misc/debug.h</a>"</font>
00036
00037 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00038 <font class="preprocessor"></font><font class="preprocessor"># include <windows.h></font>
00039 <font class="preprocessor">#else</font>
00040 <font class="preprocessor"></font><font class="preprocessor"># include <sys/types.h></font>
00041 <font class="preprocessor"># include <sys/stat.h></font>
00042 <font class="preprocessor"># include <fcntl.h></font>
00043 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00044 <font class="preprocessor"></font>
00045 <font class="preprocessor">#include <set></font>
00046
00047 <font class="keyword">namespace </font>NLMISC
00048 {
00049
00050 <font class="comment">// Include inlines functions</font>
00051 <font class="preprocessor">#include "<a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html">nel/misc/heap_allocator_inline.h</a>"</font>
00052
<a name="l00053"></a><a class="code" href="misc_2heap__allocator_8cpp.html#a0">00053</a> <font class="preprocessor">#define NL_HEAP_SB_CATEGORY "_SmlBlk"</font>
<a name="l00054"></a><a class="code" href="misc_2heap__allocator_8cpp.html#a1">00054</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_HEAP_CATEGORY_BLOCK_CATEGORY "_MemCat"</font>
<a name="l00055"></a><a class="code" href="misc_2heap__allocator_8cpp.html#a2">00055</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_HEAP_MEM_DEBUG_CATEGORY "_MemDb"</font>
<a name="l00056"></a><a class="code" href="misc_2heap__allocator_8cpp.html#a3">00056</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_HEAP_UNKNOWN_CATEGORY "Unknown"</font>
00057 <font class="preprocessor"></font>
00058 <font class="keywordtype">void</font> <a class="code" href="namespaceNLMISC.html#a296">CHeapAllocatorOutputError</a> (<font class="keyword">const</font> <font class="keywordtype">char</font> *str)
00059 {
00060 fprintf (stderr, str);
00061 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00062 <font class="preprocessor"></font> OutputDebugString (str);
00063 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00064 <font class="preprocessor"></font>}
00065
00066 <font class="comment">// *********************************************************</font>
00067 <font class="comment">// Constructors / desctrutors</font>
00068 <font class="comment">// *********************************************************</font>
00069
<a name="l00070"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a0">00070</a> CHeapAllocator::CHeapAllocator (uint mainBlockSize, uint blockCount, TBlockAllocationMode blockAllocationMode,
00071 TOutOfMemoryMode outOfMemoryMode)
00072 {
00073 <font class="comment">// Critical section</font>
00074 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
00075
00076 <font class="comment">// Allocator name</font>
00077 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o9">_Name</a>[0] = 0;
00078
00079 <font class="comment">// Check size of structures must be aligned</font>
00080 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((<font class="keyword">sizeof</font> (CNodeBegin) & (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#u7u3">Align</a>-1)) == 0);
00081 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((NL_HEAP_NODE_END_SIZE & (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#u7u3">Align</a>-1)) == 0);
00082 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((<font class="keyword">sizeof</font> (CFreeNode) & (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#u7u3">Align</a>-1)) == 0);
00083
00084 <font class="comment">// Check small block sizes</font>
00085 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s15">FirstSmallBlock</a>&(<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s14">SmallBlockGranularity</a>-1)) == 0);
00086 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s16">LastSmallBlock</a>&(<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s14">SmallBlockGranularity</a>-1)) == 0);
00087
00088 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a> = NULL;
00089 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o0">_MainBlockSize</a> = mainBlockSize;
00090 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o1">_BlockCount</a> = blockCount;
00091 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o2">_BlockAllocationMode</a> = blockAllocationMode;
00092 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o3">_OutOfMemoryMode</a> = outOfMemoryMode;
00093 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
00094 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00095 <font class="preprocessor"></font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o4">_AlwaysCheck</a> = <font class="keyword">false</font>;
00096 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00097 <font class="preprocessor"></font>
00098 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m0">Left</a> = &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
00099 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m1">Right</a> = &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
00100 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m2">Parent</a> = NULL;
00101
00102 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (&<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>);
00103
00104 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00105 <font class="preprocessor"></font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o10">_AllocateCount</a> = 0;
00106 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00107 <font class="preprocessor"></font>
00108 <font class="comment">// *********************************************************</font>
00109 <font class="comment">// Small Block</font>
00110 <font class="comment">// *********************************************************</font>
00111
00112 <font class="comment">// The free smallblock array by size</font>
00113 <font class="keyword">const</font> uint smallBlockSizeCount = NL_SMALLBLOCK_COUNT;
00114 uint smallBlockSize;
00115 <font class="keywordflow">for</font> (smallBlockSize=0; smallBlockSize<smallBlockSizeCount; smallBlockSize++)
00116 {
00117 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o11">_FreeSmallBlocks</a>[smallBlockSize] = NULL;
00118 }
00119
00120 <font class="comment">// No small block</font>
00121 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a> = NULL;
00122
00123 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
00124 }
00125
00126 <font class="comment">// *********************************************************</font>
00127
<a name="l00128"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a1">00128</a> CHeapAllocator::~CHeapAllocator ()
00129 {
00130 <font class="comment">// Release all memory used</font>
00131 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a6">releaseMemory</a> ();
00132 }
00133
00134 <font class="comment">// *********************************************************</font>
00135
<a name="l00136"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#c3">00136</a> <font class="keywordtype">void</font> CHeapAllocator::insert (CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
00137 {
00138 CHeapAllocator::CFreeNode *current, *parent;
00139
00140 <font class="comment">// Find future parent</font>
00141 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>;
00142 parent = NULL;
00143 <font class="keywordflow">while</font> (current != &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>)
00144 {
00145 parent = current;
00146 current = (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f5">getNode</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)) <= <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f5">getNode</a> (current)) ) ? current-><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m0">Left</a> : current-><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CFreeNode.html#m1">Right</a>;
00147 }
00148
00149 <font class="comment">// Setup new node</font>
00150 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent = parent;
00151 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Left = &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
00152 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Right = &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
00153 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00154
00155 <font class="comment">// Insert node in tree</font>
00156 <font class="keywordflow">if</font> (parent)
00157 {
00158 <font class="keywordflow">if</font>(<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f5">getNode</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)) <= <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f5">getNode</a> (parent)))
00159 parent->Left = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00160 <font class="keywordflow">else</font>
00161 parent->Right = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00162 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (parent);
00163 }
00164 <font class="keywordflow">else</font>
00165 {
00166 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00167 }
00168
00169 <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>);
00170
00171 <font class="comment">// Maintain Red-Black tree balance</font>
00172 <font class="comment">// After inserting node x</font>
00173 <font class="comment">// Check Red-Black properties</font>
00174
00175 <font class="keywordflow">while</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> != <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> && <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent))
00176 {
00177 <font class="comment">// We have a violation</font>
00178 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent->Left)
00179 {
00180 CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent->Right;
00181 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>))
00182 {
00183 <font class="comment">// Uncle is RED</font>
00184 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00185 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00186 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent);
00187
00188 <font class="comment">// Crc node</font>
00189 <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>);
00190 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00191 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent);
00192
00193 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent;
00194 }
00195 <font class="keywordflow">else</font>
00196 {
00197 <font class="comment">// Uncle is Black</font>
00198 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Right)
00199 {
00200 <font class="comment">// Make x a left child</font>
00201 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent;
00202 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c1">rotateLeft</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00203 }
00204
00205 <font class="comment">// Recolor and rotate</font>
00206 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00207 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent);
00208
00209 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c2">rotateRight</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent);
00210
00211 <font class="comment">// Crc node</font>
00212 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00213 }
00214 }
00215 <font class="keywordflow">else</font>
00216 {
00217 <font class="comment">// Mirror image of above code</font>
00218 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>->Parent->Parent->Left;
00219 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>))
00220 {
00221 <font class="comment">// Uncle is Red</font>
00222 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00223 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00224 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent);
00225
00226 <font class="comment">// Crc node</font>
00227 <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>);
00228 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00229 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent);
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>->Parent->Parent;
00232 }
00233 <font class="keywordflow">else</font>
00234 {
00235 <font class="comment">// Uncle is Black</font>
00236 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Left)
00237 {
00238 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent;
00239 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c2">rotateRight</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00240 }
00241 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00242 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent);
00243
00244 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c1">rotateLeft</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Parent);
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="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00248 }
00249 }
00250 }
00251 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>);
00252
00253 <font class="comment">// Crc node</font>
00254 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a2">NL_UPDATE_MAGIC_NUMBER_FREE_NODE</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>);
00255 }
00256
00257 <font class="comment">// *********************************************************</font>
00258
<a name="l00259"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#c4">00259</a> <font class="keywordtype">void</font> CHeapAllocator::erase (CHeapAllocator::CFreeNode *<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>)
00260 {
00261 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>;
00262 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>->Left == &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a> || <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>->Right == &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>)
00263 {
00264 <font class="comment">// y has a NULL node as a child</font>
00265 <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>;
00266 }
00267 <font class="keywordflow">else</font>
00268 {
00269 <font class="comment">// Find tree successor with a &_NullNode.FreeNode node as a child</font>
00270 <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>->Right;
00271 <font class="keywordflow">while</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Left != &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>)
00272 <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>->Left;
00273 }
00274
00275 <font class="comment">// x is y's only child</font>
00276 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Left != &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>)
00277 <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>->Left;
00278 <font class="keywordflow">else</font>
00279 <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>->Right;
00280
00281 <font class="comment">// Remove y from the parent chain</font>
00282 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent;
00283
00284 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent)
00285 {
00286 <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>->Parent->Left)
00287 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent->Left = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00288 <font class="keywordflow">else</font>
00289 {
00290 <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>->Parent->Right);
00291 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent->Right = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00292 }
00293 <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>->Parent);
00294 }
00295 <font class="keywordflow">else</font>
00296 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00297
00298 <font class="keywordtype">bool</font> yRed = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00299
00300 <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>)
00301 {
00302 <font class="comment">// Replace y by z</font>
00303 *<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>;
00304 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f18">setNodeColor</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>));
00305 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent)
00306 {
00307 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent->Left == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>)
00308 {
00309 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent->Left = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00310 }
00311 <font class="keywordflow">else</font>
00312 {
00313 <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>->Parent->Right == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>);
00314 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent->Right = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00315 }
00316 }
00317 <font class="keywordflow">else</font>
00318 {
00319 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>);
00320 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00321 }
00322
00323 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Left)
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>->Left->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>->Left->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>->Left);
00329 }
00330 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Right)
00331 {
00332 <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>->Right->Parent == <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>);
00333 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Right->Parent = <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00334
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>->Right);
00336 }
00337 }
00338
00339 <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>);
00340 <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>);
00341 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>->Parent)
00342 <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>->Parent);
00343
00344 <font class="keywordflow">if</font> (!yRed)
00345 {
00346 <font class="comment">// Maintain Red-Black tree balance</font>
00347 <font class="comment">// After deleting node x</font>
00348 <font class="keywordflow">while</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> != <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> && <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>))
00349 {
00350 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent->Left)
00351 {
00352 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>->Parent->Right;
00353 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>))
00354 {
00355 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00356 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00357 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c1">rotateLeft</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00358
00359 <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>);
00360
00361 <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>->Parent->Right;
00362 }
00363 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Left) && <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Right))
00364 {
00365 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00366 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent;
00367
00368 <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>);
00369 }
00370 <font class="keywordflow">else</font>
00371 {
00372 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Right))
00373 {
00374 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Left);
00375 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00376 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c2">rotateRight</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00377 <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>->Parent->Right;
00378 }
00379 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f18">setNodeColor</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent));
00380 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00381 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Right);
00382 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c1">rotateLeft</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00383
00384 <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>);
00385 <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>->Right);
00386
00387 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>;
00388 }
00389 }
00390 <font class="keywordflow">else</font>
00391 {
00392 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>->Parent->Left;
00393 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>))
00394 {
00395 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00396 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00397 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c2">rotateRight</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00398
00399 <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>);
00400
00401 <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>->Parent->Left;
00402 }
00403 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Right) && <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Left) )
00404 {
00405 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00406 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent;
00407
00408 <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>);
00409 }
00410 <font class="keywordflow">else</font>
00411 {
00412 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f13">isNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Left) )
00413 {
00414 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Right);
00415 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f19">setNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00416 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c1">rotateLeft</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>);
00417 <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>->Parent->Left;
00418 }
00419 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f18">setNodeColor</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f12">isNodeRed</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent) );
00420 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00421 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>->Left);
00422
00423 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c2">rotateRight</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>->Parent);
00424
00425 <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>);
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#a367">w</a>->Left);
00427
00428 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>;
00429 }
00430 }
00431 }
00432 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f20">setNodeBlack</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00433 <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>);
00434 }
00435 }
00436
00437 <font class="comment">// *********************************************************</font>
00438 <font class="comment">// Node methods</font>
00439 <font class="comment">// *********************************************************</font>
00440
<a name="l00441"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#c6">00441</a> CHeapAllocator::CNodeBegin *CHeapAllocator::splitNode (CNodeBegin *node, uint newSize)
00442 {
00443 <font class="comment">// Should be smaller than node size</font>
00444 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (newSize <= <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (node));
00445
00446 <font class="comment">// Align size</font>
00447 uint allignedSize = (newSize&~(<a class="code" href="classNLMISC_1_1CHeapAllocator.html#u7u3">Align</a>-1)) + (( (newSize&(<a class="code" href="classNLMISC_1_1CHeapAllocator.html#u7u3">Align</a>-1))==0 ) ? 0 : <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u7u3">Align</a>);
00448 <font class="keywordflow">if</font> (allignedSize <= <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u8u5">UserDataBlockSizeMin</a>)
00449 allignedSize = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u8u5">UserDataBlockSizeMin</a>;
00450
00451 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00452 <font class="preprocessor"></font> <font class="comment">// End magic number aligned on new size</font>
00453 node->EndMagicNumber = (uint32*)((uint8*)node + newSize + <font class="keyword">sizeof</font> (CNodeBegin));
00454 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00455 <font class="preprocessor"></font>
00456 <font class="comment">// Rest is empty ?</font>
00457 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) - allignedSize < <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u8u5">UserDataBlockSizeMin</a> + <font class="keyword">sizeof</font> (CNodeBegin) + NL_HEAP_NODE_END_SIZE )
00458 <font class="comment">// No split</font>
00459 <font class="keywordflow">return</font> NULL;
00460
00461 <font class="comment">// New node begin structure</font>
00462 CNodeBegin *newNode = (CNodeBegin*)((uint8*)node + <font class="keyword">sizeof</font> (CNodeBegin) + allignedSize + NL_HEAP_NODE_END_SIZE );
00463
00464 <font class="comment">// Fill the new node header</font>
00465
00466 <font class="comment">// Size</font>
00467 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f17">setNodeSize</a> (newNode, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) - allignedSize - <font class="keyword">sizeof</font> (CNodeBegin) - NL_HEAP_NODE_END_SIZE);
00468
00469 <font class="comment">// Set the node free</font>
00470 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f14">setNodeFree</a> (newNode);
00471
00472 <font class="comment">// Set the previous node pointer</font>
00473 newNode->Previous = node;
00474
00475 <font class="comment">// Last flag</font>
00476 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f16">setNodeLast</a> (newNode, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f10">isNodeLast</a> (node));
00477
00478 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00479 <font class="preprocessor"></font> <font class="comment">// Begin markers</font>
00480 memset (newNode->BeginMarkers, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s3">BeginNodeMarkers</a>, CNodeBegin::MarkerSize-1);
00481 newNode->BeginMarkers[CNodeBegin::MarkerSize-1] = 0;
00482
00483 <font class="comment">// End pointer</font>
00484 newNode->EndMagicNumber = (uint32*)((uint8*)newNode + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (newNode) + <font class="keyword">sizeof</font> (CNodeBegin));
00485
00486 <font class="comment">// End markers</font>
00487 CNodeEnd *endNode = (CNodeEnd*)((uint8*)newNode + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (newNode) + <font class="keyword">sizeof</font> (CNodeBegin));
00488 memset (endNode->EndMarkers, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s4">EndNodeMarkers</a>, CNodeEnd::MarkerSize-1);
00489 endNode->EndMarkers[CNodeEnd::MarkerSize-1] = 0;
00490
00491 <font class="comment">// No source informations</font>
00492 newNode->File = NULL;
00493 newNode->Line = 0xffff;
00494 node->AllocateNumber = 0xffffffff;
00495 memset (newNode->Category, 0, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s2">CategoryStringLength</a>);
00496
00497 <font class="comment">// Heap pointer</font>
00498 newNode->Heap = <font class="keyword">this</font>;
00499 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00500 <font class="preprocessor"></font>
00501 <font class="comment">// Get next node</font>
00502 CNodeBegin *next = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (node);
00503 <font class="keywordflow">if</font> (next)
00504 {
00505 <font class="comment">// Set previous</font>
00506 next->Previous = newNode;
00507
00508 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (next);
00509 }
00510
00511 <font class="comment">// Should be big enough</font>
00512 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (newNode) >= <a class="code" href="classNLMISC_1_1CHeapAllocator.html#u8u5">UserDataBlockSizeMin</a>);
00513
00514 <font class="comment">// New size of the first node</font>
00515 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f17">setNodeSize</a> (node, allignedSize);
00516
00517 <font class="comment">// No more the last</font>
00518 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f16">setNodeLast</a> (node, <font class="keyword">false</font>);
00519
00520 <font class="comment">// Return new node</font>
00521 <font class="keywordflow">return</font> newNode;
00522 }
00523
00524 <font class="comment">// *********************************************************</font>
00525
<a name="l00526"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#f23">00526</a> <font class="keywordtype">void</font> CHeapAllocator::mergeNode (CNodeBegin *node)
00527 {
00528 <font class="comment">// Get the previous node to merge with</font>
00529 CNodeBegin *previous = node->Previous;
00530 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (previous) == node);
00531 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (previous);
00532 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (previous));
00533
00534 <font class="comment">// New size</font>
00535 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f17">setNodeSize</a> (previous, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (previous) + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) + <font class="keyword">sizeof</font> (CNodeBegin) + NL_HEAP_NODE_END_SIZE);
00536
00537 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00538 <font class="preprocessor"></font> <font class="comment">// Set end pointers</font>
00539 previous->EndMagicNumber = (uint32*)((uint8*)previous + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (previous) + <font class="keyword">sizeof</font> (CNodeBegin));
00540 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00541 <font class="preprocessor"></font>
00542 <font class="comment">// Get the next node to relink</font>
00543 CNodeBegin *next = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (node);
00544 <font class="keywordflow">if</font> (next)
00545 {
00546 <font class="comment">// Relink</font>
00547 next->Previous = previous;
00548
00549 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (next);
00550 }
00551
00552 <font class="comment">// Get the last flag</font>
00553 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f16">setNodeLast</a> (previous, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f10">isNodeLast</a> (node));
00554
00555 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00556 <font class="preprocessor"></font>
00557 <font class="comment">// todo align</font>
00558
00559 <font class="comment">// Clear the node informations</font>
00560 memset (((uint8*)node + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) + <font class="keyword">sizeof</font> (CNodeBegin)), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s7">DeletedMemory</a>, NL_HEAP_NODE_END_SIZE);
00561 memset (node, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s7">DeletedMemory</a>, <font class="keyword">sizeof</font> (CNodeBegin));
00562 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00563 <font class="preprocessor"></font>}
00564
00565
00566 <font class="comment">// *********************************************************</font>
00567 <font class="comment">// *********************************************************</font>
00568
00569 <font class="comment">// Synchronized methods</font>
00570
00571 <font class="comment">// *********************************************************</font>
00572 <font class="comment">// *********************************************************</font>
00573
00574
<a name="l00575"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#c7">00575</a> <font class="keywordtype">void</font> CHeapAllocator::initEmptyBlock (CMainBlock& mainBlock)
00576 {
00577 <font class="comment">// Get the node pointer</font>
00578 CNodeBegin *node = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (&mainBlock);
00579
00580 <font class="comment">// Allocated size remaining after alignment</font>
00581 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((uint32)node - (uint32)mainBlock.Ptr >= 0);
00582 uint allocSize = mainBlock.Size - ((uint32)node - (uint32)mainBlock.Ptr);
00583
00584 <font class="comment">// *** Fill the new node header</font>
00585
00586 <font class="comment">// User data size</font>
00587 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f17">setNodeSize</a> (node, allocSize-<font class="keyword">sizeof</font> (CNodeBegin)-NL_HEAP_NODE_END_SIZE);
00588
00589 <font class="comment">// Node is free</font>
00590 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f14">setNodeFree</a> (node);
00591
00592 <font class="comment">// Node is last</font>
00593 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f16">setNodeLast</a> (node, <font class="keyword">true</font>);
00594
00595 <font class="comment">// No previous node</font>
00596 node->Previous = NULL;
00597
00598 <font class="comment">// Debug info</font>
00599 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00600 <font class="preprocessor"></font> <font class="comment">// End magic number</font>
00601 node->EndMagicNumber = (uint32*)((uint8*)node + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) + <font class="keyword">sizeof</font> (CNodeBegin));
00602
00603 <font class="comment">// Begin markers</font>
00604 memset (node->BeginMarkers, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s3">BeginNodeMarkers</a>, CNodeBegin::MarkerSize-1);
00605 node->BeginMarkers[CNodeBegin::MarkerSize-1] = 0;
00606
00607 <font class="comment">// End markers</font>
00608 CNodeEnd *endNode = (CNodeEnd*)node->EndMagicNumber;
00609 memset (endNode->EndMarkers, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s4">EndNodeMarkers</a>, CNodeEnd::MarkerSize-1);
00610 endNode->EndMarkers[CNodeEnd::MarkerSize-1] = 0;
00611
00612 <font class="comment">// Unallocated memory</font>
00613 memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s5">UnallocatedMemory</a>, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (node) );
00614
00615 <font class="comment">// No source file</font>
00616 memset (node->Category, 0, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s2">CategoryStringLength</a>);
00617 node->File = NULL;
00618 node->Line = 0xffff;
00619 node->AllocateNumber = 0xffffffff;
00620
00621 <font class="comment">// Heap pointer</font>
00622 node->Heap = <font class="keyword">this</font>;
00623
00624 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
00625 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00626 <font class="preprocessor"></font>}
00627
00628 <font class="comment">// *********************************************************</font>
00629
<a name="l00630"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#d0">00630</a> uint CHeapAllocator::getBlockSize (<font class="keywordtype">void</font> *block)
00631 {
00632 <font class="comment">// Get the node pointer</font>
00633 CNodeBegin *node = (CNodeBegin*) ((uint)block - <font class="keyword">sizeof</font> (CNodeBegin));
00634
00635 <font class="keywordflow">return</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (((CNodeBegin*) ((uint)block - <font class="keyword">sizeof</font> (CNodeBegin))));
00636 }
00637
00638 <font class="comment">// *********************************************************</font>
00639
00640 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATION_NDEBUG</font>
00641 <font class="preprocessor"></font><font class="keywordtype">void</font> *CHeapAllocator::allocate (uint size)
00642 <font class="preprocessor">#else // NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l00643"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a2">00643</a> <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)
00644 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00645 <font class="preprocessor"></font>{
00646 <font class="comment">// Check size is valid</font>
00647 <font class="keywordflow">if</font> (size != 0)
00648 {
00649 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00650 <font class="preprocessor"></font> <font class="comment">// If category is NULL</font>
00651 <font class="keywordflow">if</font> (category == NULL)
00652 {
00653 <font class="comment">// Get the current category</font>
00654 CCategory *cat = (CCategory*)_CategoryStack.getPointer ();
00655 <font class="keywordflow">if</font> (cat)
00656 {
00657 category = cat->Name;
00658 }
00659 <font class="keywordflow">else</font>
00660 {
00661 <font class="comment">// Not yet initialised</font>
00662 category = <a class="code" href="misc_2heap__allocator_8cpp.html#a3">NL_HEAP_UNKNOWN_CATEGORY</a>;
00663 }
00664 }
00665
00666 <font class="comment">// Checks ?</font>
00667 <font class="keywordflow">if</font> (_AlwaysCheck)
00668 {
00669 <font class="comment">// Check heap integrity</font>
00670 internalCheckHeap (<font class="keyword">true</font>);
00671 }
00672
00673 <font class="comment">// Check breakpoints</font>
00674 <font class="comment">/*if (_Breakpoints.find (_AllocateCount) != _Breakpoints.end())</font>
00675 <font class="comment"> {</font>
00676 <font class="comment"> // ********</font>
00677 <font class="comment"> // * STOP *</font>
00678 <font class="comment"> // ********</font>
00679 <font class="comment"> // * Breakpoints allocation</font>
00680 <font class="comment"> // ********</font>
00681 <font class="comment"> NL_ALLOC_STOP;</font>
00682 <font class="comment"> }*/</font>
00683 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00684 <font class="preprocessor"></font>
00685 <font class="comment">// Small or largs block ?</font>
00686 <font class="preprocessor">#ifdef NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00687 <font class="preprocessor"></font> <font class="keywordflow">if</font> (0)
00688 <font class="preprocessor">#else // NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00689 <font class="preprocessor"></font> <font class="keywordflow">if</font> (size <= LastSmallBlock)
00690 <font class="preprocessor">#endif// NL_HEAP_NO_SMALL_BLOCK_OPTIMIZATION</font>
00691 <font class="preprocessor"></font> {
00692 <font class="comment">// *******************</font>
00693 <font class="comment">// Small block</font>
00694 <font class="comment">// *******************</font>
00695
00696 enterCriticalSectionSB ();
00697
00698 <font class="comment">// Get pointer on the free block list</font>
00699 CNodeBegin **freeNode = (CNodeBegin **)_FreeSmallBlocks+<a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a2">NL_SIZE_TO_SMALLBLOCK_INDEX</a> (size);
00700
00701 <font class="comment">// Not found ?</font>
00702 <font class="keywordflow">if</font> (*freeNode == NULL)
00703 {
00704 leaveCriticalSectionSB ();
00705
00706 <font class="comment">// Size must be aligned</font>
00707 uint alignedSize = <a class="code" href="include_2nel_2misc_2heap__allocator_8h.html#a3">NL_ALIGN_SIZE_FOR_SMALLBLOCK</a> (size);
00708
00709 <font class="comment">// Use internal allocator</font>
00710 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 +
00711 NL_HEAP_NODE_END_SIZE), <a class="code" href="misc_2heap__allocator_8cpp.html#a0">NL_HEAP_SB_CATEGORY</a>);
00712
00713 enterCriticalSectionSB ();
00714
00715 <font class="comment">// Link this new block</font>
00716 smallBlock->Size = alignedSize;
00717 smallBlock->Next = (CSmallBlockPool*)_SmallBlockPool;
00718 _SmallBlockPool = smallBlock;
00719
00720 <font class="comment">// Initialize the block</font>
00721 uint pool;
00722 CNodeBegin *nextNode = *freeNode;
00723 <font class="keywordflow">for</font> (pool=0; pool<SmallBlockPoolSize; pool++)
00724 {
00725 <font class="comment">// Get the pool</font>
00726 CNodeBegin *node = getSmallBlock (smallBlock, pool);
00727
00728 <font class="comment">// Set as free</font>
00729 node->SizeAndFlags = alignedSize;
00730
00731 <font class="comment">// Insert in the list</font>
00732 setNextSmallBlock (node, nextNode);
00733 nextNode = node;
00734
00735 <font class="comment">// Set debug informations</font>
00736 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00737 <font class="preprocessor"></font> <font class="comment">// Set node free</font>
00738 setNodeFree (node);
00739
00740 <font class="comment">// End magic number</font>
00741 node->EndMagicNumber = (uint32*)(CNodeEnd*)((uint8*)node + getNodeSize (node) + <font class="keyword">sizeof</font> (CNodeBegin));
00742
00743 <font class="comment">// Begin markers</font>
00744 memset (node->BeginMarkers, BeginNodeMarkers, CNodeBegin::MarkerSize-1);
00745 node->BeginMarkers[CNodeBegin::MarkerSize-1] = 0;
00746
00747 <font class="comment">// End markers</font>
00748 CNodeEnd *endNode = (CNodeEnd*)((uint8*)node + getNodeSize (node) + <font class="keyword">sizeof</font> (CNodeBegin));
00749 memset (endNode->EndMarkers, EndNodeMarkers, CNodeEnd::MarkerSize-1);
00750 endNode->EndMarkers[CNodeEnd::MarkerSize-1] = 0;
00751
00752 <font class="comment">// Unallocated memory</font>
00753 memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), UnallocatedMemory, getNodeSize (node) );
00754
00755 <font class="comment">// No source file</font>
00756 memset (node->Category, 0, CategoryStringLength);
00757 node->File = NULL;
00758 node->Line = 0xffff;
00759 node->AllocateNumber = 0xffffffff;
00760
00761 <font class="comment">// Heap pointer</font>
00762 node->Heap = <font class="keyword">this</font>;
00763
00764 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
00765
00766 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00767 <font class="preprocessor"></font> }
00768
00769 <font class="comment">// Link the new blocks</font>
00770 *freeNode = nextNode;
00771 }
00772
00773 <font class="comment">// Check allocation as been done</font>
00774 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (*freeNode);
00775
00776 <font class="comment">// Get a node</font>
00777 CNodeBegin *node = *freeNode;
00778
00779 <font class="comment">// Checks</font>
00780 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (size <= getNodeSize (node));
00781 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((NL_SIZE_TO_SMALLBLOCK_INDEX (size)) < (NL_SMALLBLOCK_COUNT));
00782
00783 <font class="comment">// Relink</font>
00784 *freeNode = getNextSmallBlock (node);
00785
00786 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG </font>
00787 <font class="preprocessor"></font> <font class="comment">// Check the node CRC</font>
00788 checkNode (node, evalMagicNumber (node));
00789
00790 <font class="comment">// Set node free for checks</font>
00791 setNodeUsed (node);
00792
00793 <font class="comment">// Fill category</font>
00794 strncpy (node->Category, category, CategoryStringLength-1);
00795
00796 <font class="comment">// Source filename</font>
00797 node->File = sourceFile;
00798
00799 <font class="comment">// Source line</font>
00800 node->Line = line;
00801
00802 <font class="comment">// Allocate count</font>
00803 node->AllocateNumber = _AllocateCount++;
00804
00805 <font class="comment">// End magic number aligned on new size</font>
00806 node->EndMagicNumber = (uint32*)((uint8*)node + size + <font class="keyword">sizeof</font> (CNodeBegin));
00807
00808 <font class="comment">// Uninitialised memory</font>
00809 memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), UninitializedMemory, (uint32)(node->EndMagicNumber) - ( (uint32)node + <font class="keyword">sizeof</font>(CNodeBegin) ) );
00810
00811 <font class="comment">// Crc node</font>
00812 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
00813 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00814 <font class="preprocessor"></font>
00815 leaveCriticalSectionSB ();
00816
00817 <font class="comment">// Return the user pointer</font>
00818 <font class="keywordflow">return</font> (<font class="keywordtype">void</font>*)((uint)node + <font class="keyword">sizeof</font> (CNodeBegin));
00819 }
00820 <font class="keywordflow">else</font>
00821 {
00822 <font class="comment">// *******************</font>
00823 <font class="comment">// Large block</font>
00824 <font class="comment">// *******************</font>
00825
00826 <font class="comment">// Check size</font>
00827 <font class="keywordflow">if</font> ( (size & ~CNodeBegin::SizeMask) != 0)
00828 {
00829 <font class="comment">// ********</font>
00830 <font class="comment">// * STOP *</font>
00831 <font class="comment">// ********</font>
00832 <font class="comment">// * Attempt to allocate more than 1 Go</font>
00833 <font class="comment">// ********</font>
00834 NL_ALLOC_STOP;
00835
00836 <font class="comment">// Select outofmemory mode</font>
00837 <font class="keywordflow">if</font> (_OutOfMemoryMode == ReturnNull)
00838 <font class="keywordflow">return</font> NULL;
00839 <font class="keywordflow">else</font>
00840 <font class="keywordflow">throw</font> std::bad_alloc();
00841 }
00842
00843 enterCriticalSectionLB ();
00844
00845 <font class="comment">// Find a free node</font>
00846 CHeapAllocator::CFreeNode *freeNode = CHeapAllocator::find (size);
00847
00848 <font class="comment">// The node</font>
00849 CNodeBegin *node;
00850
00851 <font class="comment">// Node not found ?</font>
00852 <font class="keywordflow">if</font> (freeNode == NULL)
00853 {
00854 <font class="comment">// Block allocation mode</font>
00855 <font class="keywordflow">if</font> ((_BlockAllocationMode == DontGrow) && (_MainBlockList != NULL))
00856 {
00857 <font class="comment">// Select outofmemory mode</font>
00858 <font class="keywordflow">if</font> (_OutOfMemoryMode == ReturnNull)
00859 <font class="keywordflow">return</font> NULL;
00860 <font class="keywordflow">else</font>
00861 <font class="keywordflow">throw</font> std::bad_alloc();
00862 }
00863
00864 <font class="comment">// The node</font>
00865 uint8 *buffer;
00866
00867 <font class="comment">// Alloc size</font>
00868 uint allocSize;
00869
00870 <font class="comment">// Aligned size</font>
00871 uint allignedSize = (size&~(Align-1)) + (( (size&(Align-1))==0 ) ? 0 : Align);
00872 <font class="keywordflow">if</font> (allignedSize < BlockDataSizeMin)
00873 allignedSize = BlockDataSizeMin;
00874
00875 <font class="comment">// Does the node bigger than mainNodeSize ?</font>
00876 <font class="keywordflow">if</font> (allignedSize > (_MainBlockSize-<font class="keyword">sizeof</font> (CNodeBegin)-NL_HEAP_NODE_END_SIZE))
00877 <font class="comment">// Allocate a specific block</font>
00878 allocSize = allignedSize + <font class="keyword">sizeof</font> (CNodeBegin) + NL_HEAP_NODE_END_SIZE;
00879 <font class="keywordflow">else</font>
00880 <font class="comment">// Allocate a new block</font>
00881 allocSize = _MainBlockSize;
00882
00883 <font class="comment">// Allocate the buffer</font>
00884 buffer = allocateBlock (allocSize+Align);
00885
00886 <font class="comment">// Add the buffer</font>
00887 CMainBlock *mainBlock = (CMainBlock*)allocateBlock (<font class="keyword">sizeof</font>(CMainBlock));
00888 mainBlock->Size = allocSize+Align;
00889 mainBlock->Ptr = buffer;
00890 mainBlock->Next = _MainBlockList;
00891 _MainBlockList = mainBlock;
00892
00893 <font class="comment">// Init the new block</font>
00894 initEmptyBlock (*mainBlock);
00895
00896 <font class="comment">// Get the first node</font>
00897 node = getFirstNode (mainBlock);
00898 }
00899 <font class="keywordflow">else</font>
00900 {
00901 <font class="comment">// Get the node</font>
00902 node = getNode (freeNode);
00903
00904 <font class="comment">// Remove the node from free blocks and get the removed block</font>
00905 erase (freeNode);
00906 }
00907
00908 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00909 <font class="preprocessor"></font> <font class="comment">// Check the node CRC</font>
00910 checkNode (node, evalMagicNumber (node));
00911 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00912 <font class="preprocessor"></font>
00913 <font class="comment">// Split the node</font>
00914 CNodeBegin *rest = splitNode (node, size);
00915
00916 <font class="comment">// Fill informations for the first part of the node</font>
00917
00918 <font class="comment">// Clear free flag</font>
00919 setNodeUsed (node);
00920
00921 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
00922 <font class="preprocessor"></font> <font class="comment">// Fill category</font>
00923 strncpy (node->Category, category, CategoryStringLength-1);
00924
00925 <font class="comment">// Source filename</font>
00926 node->File = sourceFile;
00927
00928 <font class="comment">// Source line</font>
00929 node->Line = line;
00930
00931 <font class="comment">// Allocate count</font>
00932 node->AllocateNumber = _AllocateCount++;
00933
00934 <font class="comment">// Crc node</font>
00935 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
00936
00937 <font class="comment">// Uninitialised memory</font>
00938 memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), UninitializedMemory, (uint32)(node->EndMagicNumber) - ( (uint32)node + <font class="keyword">sizeof</font>(CNodeBegin) ) );
00939 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
00940 <font class="preprocessor"></font>
00941 <font class="comment">// Node has been splited ?</font>
00942 <font class="keywordflow">if</font> (rest)
00943 {
00944 <font class="comment">// Fill informations for the second part of the node</font>
00945
00946 <font class="comment">// Get the freeNode</font>
00947 freeNode = getFreeNode (rest);
00948
00949 <font class="comment">// Insert the free node</font>
00950 insert (freeNode);
00951
00952 <font class="comment">// Crc node</font>
00953 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (rest);
00954 }
00955
00956 <font class="comment">// Check the node size</font>
00957 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ( size <= getNodeSize (node) );
00958 <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 >= getNodeSize (node) );
00959
00960 <font class="comment">// Check pointer alignment</font>
00961 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> (((uint32)node&(Align-1)) == 0);
00962 <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))&(Align-1)) == 0);
00963
00964 <font class="comment">// Check size</font>
00965 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((uint32)node->EndMagicNumber <= (uint32)((uint8*)node+<font class="keyword">sizeof</font>(CNodeBegin)+getNodeSize (node) ));
00966 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a0">internalAssert</a> ((uint32)node->EndMagicNumber > (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)));
00967
00968 leaveCriticalSectionLB ();
00969
00970 <font class="comment">// Return the user pointer</font>
00971 <font class="keywordflow">return</font> (<font class="keywordtype">void</font>*)((uint)node + <font class="keyword">sizeof</font> (CNodeBegin));
00972 }
00973 }
00974 <font class="keywordflow">else</font>
00975 {
00976 <font class="comment">// ********</font>
00977 <font class="comment">// * STOP *</font>
00978 <font class="comment">// ********</font>
00979 <font class="comment">// * Attempt to allocate 0 bytes</font>
00980 <font class="comment">// ********</font>
00981 NL_ALLOC_STOP;
00982 <font class="keywordflow">return</font> NULL;
00983 }
00984 }
00985
00986 <font class="comment">// *********************************************************</font>
00987
<a name="l00988"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">00988</a> <font class="keywordtype">void</font> CHeapAllocator::free (<font class="keywordtype">void</font> *ptr)
00989 {
00990 <font class="comment">// Delete a null pointer ?</font>
00991 <font class="keywordflow">if</font> (ptr == NULL)
00992 {
00993 <font class="comment">// ********</font>
00994 <font class="comment">// * STOP *</font>
00995 <font class="comment">// ********</font>
00996 <font class="comment">// * Attempt to delete a NULL pointer</font>
00997 <font class="comment">// ********</font>
00998 <font class="preprocessor">#ifdef NL_HEAP_STOP_NULL_FREE</font>
00999 <font class="preprocessor"></font> NL_ALLOC_STOP;
01000 <font class="preprocessor">#endif // NL_HEAP_STOP_NULL_FREE</font>
01001 <font class="preprocessor"></font> }
01002 <font class="keywordflow">else</font>
01003 {
01004 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01005 <font class="preprocessor"></font> <font class="comment">// Checks ?</font>
01006 <font class="keywordflow">if</font> (_AlwaysCheck)
01007 {
01008 <font class="comment">// Check heap integrity</font>
01009 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c10">internalCheckHeap</a> (<font class="keyword">true</font>);
01010 }
01011
01012 <font class="comment">// Get the node pointer</font>
01013 CNodeBegin *node = (CNodeBegin*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin));
01014
01015 <font class="comment">// Check the node CRC</font>
01016 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c13">enterCriticalSectionSB</a> ();
01017 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c15">enterCriticalSectionLB</a> ();
01018 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">checkNode</a> (node, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (node));
01019 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c16">leaveCriticalSectionLB</a> ();
01020 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c14">leaveCriticalSectionSB</a> ();
01021 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01022 <font class="preprocessor"></font>
01023 <font class="comment">// Large or small block ?</font>
01024 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATION_NDEBUG</font>
01025 <font class="preprocessor"></font> uint size = (((CNodeBegin*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin))))->SizeAndFlags;
01026 <font class="preprocessor">#else // NL_HEAP_ALLOCATION_NDEBUG</font>
01027 <font class="preprocessor"></font> uint size = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (((CNodeBegin*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin))));
01028 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01029 <font class="preprocessor"></font> <font class="keywordflow">if</font> (size <= <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s16">LastSmallBlock</a>)
01030 {
01031 <font class="comment">// *******************</font>
01032 <font class="comment">// Small block</font>
01033 <font class="comment">// *******************</font>
01034
01035 <font class="comment">// Check the node has not been deleted</font>
01036 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (node))
01037 {
01038 <font class="comment">// ********</font>
01039 <font class="comment">// * STOP *</font>
01040 <font class="comment">// ********</font>
01041 <font class="comment">// * Attempt to delete a pointer already deleted</font>
01042 <font class="comment">// ********</font>
01043 <font class="comment">// * (*node): the already deleted node</font>
01044 <font class="comment">// ********</font>
01045 NL_ALLOC_STOP;
01046 }
01047 <font class="keywordflow">else</font>
01048 {
01049 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c13">enterCriticalSectionSB</a> ();
01050
01051 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01052 <font class="preprocessor"></font> <font class="comment">// Uninitialised memory</font>
01053 memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s7">DeletedMemory</a>, size );
01054
01055 <font class="comment">// Set end pointers</font>
01056 node->EndMagicNumber = (uint32*)((uint8*)node + size + <font class="keyword">sizeof</font> (CNodeBegin));
01057
01058 <font class="comment">// Mark has free</font>
01059 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f14">setNodeFree</a> (node);
01060 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01061 <font class="preprocessor"></font>
01062 <font class="comment">// Add in the free list</font>
01063 CNodeBegin **freeNode = (CNodeBegin **)<a class="code" href="classNLMISC_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);
01064 ((CNodeBegin*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin)))->Previous = *freeNode;
01065 *freeNode = ((CNodeBegin*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin)));
01066
01067 <font class="comment">// Update smallblock crc</font>
01068 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
01069
01070 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c14">leaveCriticalSectionSB</a> ();
01071 }
01072 }
01073 <font class="keywordflow">else</font>
01074 {
01075 <font class="preprocessor">#ifdef NL_HEAP_ALLOCATION_NDEBUG</font>
01076 <font class="preprocessor"></font> <font class="comment">// Get the real size</font>
01077 size = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (((CNodeBegin*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin))));
01078 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01079 <font class="preprocessor"></font>
01080 <font class="comment">// Get the node pointer</font>
01081 CNodeBegin *node = (CNodeBegin*) ((uint)ptr - <font class="keyword">sizeof</font> (CNodeBegin));
01082
01083 <font class="comment">// Check the node has not been deleted</font>
01084 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (node))
01085 {
01086 <font class="comment">// ********</font>
01087 <font class="comment">// * STOP *</font>
01088 <font class="comment">// ********</font>
01089 <font class="comment">// * Attempt to delete a pointer already deleted</font>
01090 <font class="comment">// ********</font>
01091 <font class="comment">// * (*node): the already deleted node</font>
01092 <font class="comment">// ********</font>
01093 NL_ALLOC_STOP;
01094 }
01095 <font class="keywordflow">else</font>
01096 {
01097 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c15">enterCriticalSectionLB</a> ();
01098
01099 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01100 <font class="preprocessor"></font> <font class="comment">// Uninitialised memory</font>
01101 memset ((uint8*)node + <font class="keyword">sizeof</font>(CNodeBegin), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s7">DeletedMemory</a>, size );
01102
01103 <font class="comment">// Set end pointers</font>
01104 node->EndMagicNumber = (uint32*)((uint8*)node + size + <font class="keyword">sizeof</font> (CNodeBegin));
01105 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01106 <font class="preprocessor"></font>
01107 <font class="comment">// Mark has free</font>
01108 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f14">setNodeFree</a> (node);
01109
01110 <font class="comment">// *******************</font>
01111 <font class="comment">// Large block</font>
01112 <font class="comment">// *******************</font>
01113
01114 <font class="comment">// A free node</font>
01115 CHeapAllocator::CFreeNode *freeNode = NULL;
01116
01117 <font class="comment">// Previous node</font>
01118 CNodeBegin *previous = node->Previous;
01119 <font class="keywordflow">if</font> (previous)
01120 {
01121 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01122 <font class="preprocessor"></font> <font class="comment">// Check the previous node</font>
01123 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">checkNode</a> (previous, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (previous));
01124 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01125 <font class="preprocessor"></font>
01126 <font class="comment">// Is it free ?</font>
01127 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (previous))
01128 {
01129 <font class="comment">// Merge the two nodes</font>
01130 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f23">mergeNode</a> (node);
01131
01132 <font class="comment">// Get its free node</font>
01133 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c4">erase</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f3">getFreeNode</a> (previous));
01134
01135 <font class="comment">// Curent node</font>
01136 node = previous;
01137 }
01138 }
01139
01140 <font class="comment">// Mark has free</font>
01141 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f14">setNodeFree</a> (node);
01142
01143 <font class="comment">// Next node</font>
01144 CNodeBegin *next = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (node);
01145 <font class="keywordflow">if</font> (next)
01146 {
01147 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01148 <font class="preprocessor"></font> <font class="comment">// Check the next node</font>
01149 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">checkNode</a> (next, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (next));
01150 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01151 <font class="preprocessor"></font>
01152 <font class="comment">// Is it free ?</font>
01153 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (next))
01154 {
01155 <font class="comment">// Free the new one</font>
01156 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c4">erase</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f3">getFreeNode</a> (next));
01157
01158 <font class="comment">// Merge the two nodes</font>
01159 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f23">mergeNode</a> (next);
01160 }
01161 }
01162
01163 <font class="comment">// Insert it into the tree</font>
01164 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c3">insert</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f3">getFreeNode</a> (node));
01165
01166 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
01167
01168 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c16">leaveCriticalSectionLB</a> ();
01169 }
01170 }
01171 }
01172 }
01173
01174 <font class="comment">// *********************************************************</font>
01175 <font class="comment">// Statistics</font>
01176 <font class="comment">// *********************************************************</font>
01177
<a name="l01178"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a16">01178</a> uint CHeapAllocator::getAllocatedMemory ()<font class="keyword"> const</font>
01179 <font class="keyword"></font>{
01180 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01181
01182 <font class="comment">// Sum allocated memory</font>
01183 uint memory = 0;
01184
01185 <font class="comment">// For each small block</font>
01186 CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01187 <font class="keywordflow">while</font> (currentSB)
01188 {
01189 <font class="comment">// For each node in this small block pool</font>
01190 uint block;
01191 <font class="keywordflow">for</font> (block=0; block<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>; block++)
01192 {
01193 <font class="comment">// Get the node</font>
01194 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01195
01196 <font class="comment">// Node allocated ?</font>
01197 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01198 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a>;
01199 }
01200
01201 <font class="comment">// Next block</font>
01202 currentSB = currentSB->Next;
01203 }
01204
01205 <font class="comment">// For each main block</font>
01206 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01207 <font class="keywordflow">while</font> (currentBlock)
01208 {
01209 <font class="comment">// Get the first node</font>
01210 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01211 <font class="keywordflow">while</font> (current)
01212 {
01213 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01214 <font class="preprocessor"></font> <font class="comment">// Check node</font>
01215 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">checkNode</a> (current, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (current));
01216 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01217 <font class="preprocessor"></font>
01218 <font class="comment">// Node allocated ? Don't sum small blocks..</font>
01219 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current) && (strcmp (current->Category, <a class="code" href="misc_2heap__allocator_8cpp.html#a0">NL_HEAP_SB_CATEGORY</a>) != 0))
01220 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a>;
01221
01222 <font class="comment">// Next node</font>
01223 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01224 }
01225
01226 <font class="comment">// Next block</font>
01227 currentBlock = currentBlock->Next;
01228 }
01229
01230 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01231
01232 <font class="comment">// Return memory used</font>
01233 <font class="keywordflow">return</font> memory;
01234 }
01235
01236 <font class="comment">// *********************************************************</font>
01237
01238 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l01239"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a27">01239</a> <font class="preprocessor"></font>uint CHeapAllocator::debugGetAllocatedMemoryByCategory (<font class="keyword">const</font> <font class="keywordtype">char</font>* category)<font class="keyword"> const</font>
01240 <font class="keyword"></font>{
01241 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01242
01243 <font class="comment">// Sum allocated memory</font>
01244 uint memory = 0;
01245
01246 <font class="comment">// For each small block</font>
01247 CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01248 <font class="keywordflow">while</font> (currentSB)
01249 {
01250 <font class="comment">// For each node in this small block pool</font>
01251 uint block;
01252 <font class="keywordflow">for</font> (block=0; block<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>; block++)
01253 {
01254 <font class="comment">// Get the node</font>
01255 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01256
01257 <font class="comment">// Node allocated ?</font>
01258 <font class="keywordflow">if</font> ((<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current)) && (strcmp (current->Category, category)==0))
01259 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
01260
01261 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
01262 }
01263
01264 <font class="comment">// Next block</font>
01265 currentSB = currentSB->Next;
01266 }
01267
01268 <font class="comment">// For each main block</font>
01269 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01270 <font class="keywordflow">while</font> (currentBlock)
01271 {
01272 <font class="comment">// Get the first node</font>
01273 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01274 <font class="keywordflow">while</font> (current)
01275 {
01276 <font class="comment">// Node allocated ?</font>
01277 <font class="keywordflow">if</font> ((<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current)) && (strcmp (current->Category, category)==0))
01278 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
01279
01280 <font class="comment">// Next node</font>
01281 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01282 }
01283
01284 <font class="comment">// Next block</font>
01285 currentBlock = currentBlock->Next;
01286 }
01287
01288 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01289
01290 <font class="comment">// Return memory used</font>
01291 <font class="keywordflow">return</font> memory;
01292 }
01293 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01294 <font class="preprocessor"></font>
01295 <font class="comment">// *********************************************************</font>
01296
01297 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l01298"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a24">01298</a> <font class="preprocessor"></font>uint CHeapAllocator::debugGetDebugInfoSize ()<font class="keyword"> const</font>
01299 <font class="keyword"></font>{
01300 <font class="comment">// Return memory used</font>
01301 <font class="keywordflow">return</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a25">debugGetSBDebugInfoSize</a> () + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a26">debugGetLBDebugInfoSize</a> ();
01302 }
01303
<a name="l01304"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a26">01304</a> uint CHeapAllocator::debugGetLBDebugInfoSize ()<font class="keyword"> const</font>
01305 <font class="keyword"></font>{
01306 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01307
01308 <font class="comment">// Sum memory used by debug header</font>
01309 uint memory = 0;
01310
01311 <font class="comment">// For each main block</font>
01312 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01313 <font class="keywordflow">while</font> (currentBlock)
01314 {
01315 <font class="comment">// Get the first node</font>
01316 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01317 <font class="keywordflow">while</font> (current)
01318 {
01319 <font class="comment">// Node allocated ?</font>
01320 memory += <font class="keyword">sizeof</font>(CNodeBegin) - <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a> + <font class="keyword">sizeof</font>(CNodeEnd);
01321
01322 <font class="comment">// Next node</font>
01323 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01324 }
01325
01326 <font class="comment">// Next block</font>
01327 currentBlock = currentBlock->Next;
01328 }
01329
01330 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01331
01332 <font class="comment">// Return memory used</font>
01333 <font class="keywordflow">return</font> memory;
01334 }
01335
<a name="l01336"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a25">01336</a> uint CHeapAllocator::debugGetSBDebugInfoSize ()<font class="keyword"> const</font>
01337 <font class="keyword"></font>{
01338 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01339
01340 <font class="comment">// Sum memory used by debug header</font>
01341 uint memory = 0;
01342
01343 <font class="comment">// For each small blocks</font>
01344 CSmallBlockPool *pool = (CSmallBlockPool*)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01345 <font class="keywordflow">while</font> (pool)
01346 {
01347 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a> * (<font class="keyword">sizeof</font>(CNodeBegin) - <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a> + <font class="keyword">sizeof</font>(CNodeEnd));
01348
01349 <font class="comment">// Next pool</font>
01350 pool = pool->Next;
01351 }
01352
01353 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01354
01355 <font class="comment">// Return memory used</font>
01356 <font class="keywordflow">return</font> memory;
01357 }
01358 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01359 <font class="preprocessor"></font>
01360 <font class="comment">// *********************************************************</font>
01361
01362 <font class="keywordtype">void</font> <a class="code" href="namespaceNLMISC.html#a297">fprintf_int</a> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)
01363 {
01364
01365 }
01366
01367 <font class="comment">// *********************************************************</font>
01368
01369 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01370 <font class="preprocessor"></font>
<a name="l01371"></a><a class="code" href="classNLMISC_1_1CCategoryMap.html">01371</a> <font class="keyword">class </font>CCategoryMap
01372 {
01373 <font class="keyword">public</font>:
<a name="l01374"></a><a class="code" href="classNLMISC_1_1CCategoryMap.html#a0">01374</a> <a class="code" href="classNLMISC_1_1CCategoryMap.html#a0">CCategoryMap</a> ()
01375 {
01376 <a class="code" href="classNLMISC_1_1CCategoryMap.html#m0">BlockCount</a> = 0;
01377 <a class="code" href="classNLMISC_1_1CCategoryMap.html#m1">Size</a> = 0;
01378 <a class="code" href="classNLMISC_1_1CCategoryMap.html#m2">Min</a> = 0xffffffff;
01379 <a class="code" href="classNLMISC_1_1CCategoryMap.html#m3">Max</a> = 0;
01380 }
<a name="l01381"></a><a class="code" href="classNLMISC_1_1CCategoryMap.html#m0">01381</a> uint <a class="code" href="classNLMISC_1_1CCategoryMap.html#m0">BlockCount</a>;
<a name="l01382"></a><a class="code" href="classNLMISC_1_1CCategoryMap.html#m1">01382</a> uint <a class="code" href="classNLMISC_1_1CCategoryMap.html#m1">Size</a>;
<a name="l01383"></a><a class="code" href="classNLMISC_1_1CCategoryMap.html#m2">01383</a> uint <a class="code" href="classNLMISC_1_1CCategoryMap.html#m2">Min</a>;
<a name="l01384"></a><a class="code" href="classNLMISC_1_1CCategoryMap.html#m3">01384</a> uint <a class="code" href="classNLMISC_1_1CCategoryMap.html#m3">Max</a>;
01385 };
01386
<a name="l01387"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a28">01387</a> <font class="keywordtype">bool</font> CHeapAllocator::debugStatisticsReport (<font class="keyword">const</font> <font class="keywordtype">char</font>* stateFile, <font class="keywordtype">bool</font> memoryMap)
01388 {
01389 <font class="comment">// Status</font>
01390 <font class="keywordtype">bool</font> status = <font class="keyword">false</font>;
01391
01392 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a34">debugPushCategoryString</a> (<a class="code" href="misc_2heap__allocator_8cpp.html#a2">NL_HEAP_MEM_DEBUG_CATEGORY</a>);
01393
01394 <font class="comment">// Open files</font>
01395 FILE *<a class="code" href="cf__lexical_8cpp.html#a95">file</a> = fopen (stateFile, <font class="stringliteral">"wt"</font>);
01396
01397 <font class="comment">// Block map</font>
01398 <font class="keyword">typedef</font> std::map<std::string, CCategoryMap> TBlockMap;
01399 TBlockMap blockMap;
01400
01401 <font class="comment">// Both OK</font>
01402 <font class="keywordflow">if</font> (file)
01403 {
01404 <font class="comment">// **************************</font>
01405
01406 <font class="comment">// For each small block</font>
01407 uint smallBlockCount = 0;
01408 uint largeBlockCount = 0;
01409 CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01410 <font class="keywordflow">while</font> (currentSB)
01411 {
01412 <font class="comment">// For each node in this small block pool</font>
01413 uint block;
01414 <font class="keywordflow">for</font> (block=0; block<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>; block++)
01415 {
01416 <font class="comment">// Get the node</font>
01417 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01418
01419 <font class="comment">// Node allocated ?</font>
01420 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01421 {
01422 <font class="comment">// Find the node</font>
01423 TBlockMap::iterator ite = blockMap.find ((<font class="keyword">const</font> <font class="keywordtype">char</font>*)current->Category);
01424
01425 <font class="comment">// Found ?</font>
01426 <font class="keywordflow">if</font> (ite == blockMap.end ())
01427 {
01428 ite = blockMap.insert (TBlockMap::value_type (current->Category, CCategoryMap ())).first;
01429 }
01430 uint size = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a>;
01431 ite->second.BlockCount++;
01432 ite->second.Size += size;
01433 <font class="keywordflow">if</font> (size < ite->second.Min)
01434 ite->second.Min = size;
01435 <font class="keywordflow">if</font> (size > ite->second.Max)
01436 ite->second.Max = size;
01437 }
01438
01439 <font class="comment">// Next node</font>
01440 smallBlockCount++;
01441 }
01442
01443 <font class="comment">// Next block</font>
01444 currentSB = currentSB->Next;
01445 }
01446
01447 <font class="comment">// For each main block</font>
01448 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01449 <font class="keywordflow">while</font> (currentBlock)
01450 {
01451 <font class="comment">// Get the first node</font>
01452 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01453 <font class="keywordflow">while</font> (current)
01454 {
01455 <font class="comment">// Node is used ?</font>
01456 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01457 {
01458 <font class="comment">// Find the node</font>
01459 TBlockMap::iterator ite = blockMap.find ((<font class="keyword">const</font> <font class="keywordtype">char</font>*)current->Category);
01460
01461 <font class="comment">// Found ?</font>
01462 <font class="keywordflow">if</font> (ite == blockMap.end ())
01463 {
01464 ite = blockMap.insert (TBlockMap::value_type (current->Category, CCategoryMap ())).first;
01465 }
01466 uint size = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a>;
01467 ite->second.BlockCount++;
01468 ite->second.Size += size;
01469 <font class="keywordflow">if</font> (size < ite->second.Min)
01470 ite->second.Min = size;
01471 <font class="keywordflow">if</font> (size > ite->second.Max)
01472 ite->second.Max = size;
01473 }
01474
01475 <font class="comment">// Next node</font>
01476 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01477 largeBlockCount++;
01478 }
01479
01480 <font class="comment">// Next block</font>
01481 currentBlock = currentBlock->Next;
01482 }
01483
01484 <font class="comment">// Write the heap info file</font>
01485 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"HEAP STATISTICS\n"</font>);
01486 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>);
01487
01488 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="classNLMISC_1_1CHeapAllocator.html#o9">_Name</a>, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a18">getTotalMemoryUsed</a> (),
01489 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a16">getAllocatedMemory</a> (), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a17">getFreeMemory</a> (), 100.f*<a class="code" href="classNLMISC_1_1CHeapAllocator.html#a21">getFragmentationRatio</a> (), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a8">getMainBlockSize</a> (), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a10">getMainBlockCount</a> ());
01490
01491 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\nHEAP BLOCKS\n"</font>);
01492 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>);
01493
01494 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%d, %d, %d\n"</font>, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a19">getSmallBlockMemory</a> (), smallBlockCount, largeBlockCount);
01495
01496 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\nHEAP DEBUG INFOS\n"</font>);
01497 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>);
01498
01499 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%d, %d, %d\n"</font>, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a25">debugGetSBDebugInfoSize</a> (), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a26">debugGetLBDebugInfoSize</a> (), <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a24">debugGetDebugInfoSize</a> ());
01500
01501 <font class="comment">// **************************</font>
01502
01503 <font class="comment">// Write the system heap info file</font>
01504 uint systemMemory = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#d1">getAllocatedSystemMemory</a> ();
01505 uint nelSystemMemory = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a20">getAllocatedSystemMemoryByAllocator</a> ();
01506
01507 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\nSYSTEM HEAP STATISTICS\n"</font>);
01508 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>);
01509 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%d, %d, %d\n"</font>, systemMemory, nelSystemMemory, systemMemory-nelSystemMemory);
01510
01511 <font class="comment">// Write the category map file</font>
01512 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\n\nCATEGORY STATISTICS\n"</font>);
01513 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>);
01514
01515 TBlockMap::iterator ite = blockMap.begin();
01516 <font class="keywordflow">while</font> (ite != blockMap.end())
01517 {
01518 <font class="comment">// Number of small blocks</font>
01519 uint smallB[NL_SMALLBLOCK_COUNT];
01520
01521 <font class="comment">// Clean</font>
01522 uint smallBlock;
01523 <font class="keywordflow">for</font> (smallBlock=0; smallBlock<NL_SMALLBLOCK_COUNT; smallBlock++)
01524 {
01525 smallB[smallBlock] = 0;
01526 }
01527
01528 <font class="comment">// Scan small block for this category</font>
01529 currentSB = (CSmallBlockPool *)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01530 <font class="keywordflow">while</font> (currentSB)
01531 {
01532 <font class="comment">// For each node in this small block pool</font>
01533 uint block;
01534 <font class="keywordflow">for</font> (block=0; block<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>; block++)
01535 {
01536 <font class="comment">// Get the node</font>
01537 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01538
01539 <font class="comment">// Node allocated ?</font>
01540 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01541 {
01542 <font class="comment">// Good node ?</font>
01543 <font class="keywordflow">if</font> (current->Category == ite->first)
01544 {
01545 <font class="comment">// Get the small block index</font>
01546 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="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current));
01547
01548 <font class="comment">// One more node</font>
01549 smallB[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++;
01550 }
01551 }
01552 }
01553
01554 <font class="comment">// Next block</font>
01555 currentSB = currentSB->Next;
01556 }
01557
01558 <font class="comment">// Average</font>
01559 uint average = ite->second.Size / ite->second.BlockCount;
01560
01561 <font class="comment">// Print the line</font>
01562 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"%s, %d, %d, %d, %d, %d"</font>, ite->first.c_str(), ite->second.BlockCount, ite->second.Size,
01563 ite->second.Min, ite->second.Max, average);
01564
01565 <font class="comment">// Print small blocks</font>
01566 <font class="keywordflow">for</font> (smallBlock=0; smallBlock<NL_SMALLBLOCK_COUNT; smallBlock++)
01567 {
01568 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">", %d"</font>, smallB[smallBlock]);
01569 }
01570
01571 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n"</font>);
01572
01573 ite++;
01574 }
01575
01576 <font class="comment">// **************************</font>
01577
01578 <font class="comment">// Write the small block statistics</font>
01579 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\n\nSMALL BLOCK STATISTICS\n"</font>);
01580 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>);
01581
01582 <font class="comment">// Number of small blocks</font>
01583 uint count[NL_SMALLBLOCK_COUNT];
01584 uint <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a>[NL_SMALLBLOCK_COUNT];
01585
01586 uint smallBlock;
01587 <font class="keywordflow">for</font> (smallBlock=0; smallBlock<NL_SMALLBLOCK_COUNT; smallBlock++)
01588 {
01589 count[smallBlock] = 0;
01590 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a>[smallBlock] = 0;
01591 }
01592
01593 <font class="comment">// For each small block</font>
01594 currentSB = (CSmallBlockPool *)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01595 <font class="keywordflow">while</font> (currentSB)
01596 {
01597 <font class="comment">// For each node in this small block pool</font>
01598 uint block;
01599 <font class="keywordflow">for</font> (block=0; block<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>; block++)
01600 {
01601 <font class="comment">// Get the node</font>
01602 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01603
01604 <font class="comment">// Get the small block index</font>
01605 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="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current));
01606
01607 <font class="comment">// Add a block</font>
01608 count[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++;
01609
01610 <font class="comment">// Node allocated ?</font>
01611 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (current))
01612 {
01613 <font class="comment">// Add a free block</font>
01614 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++;
01615 }
01616
01617 <font class="comment">// Next node</font>
01618 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01619 }
01620
01621 <font class="comment">// Next block</font>
01622 currentSB = currentSB->Next;
01623 }
01624
01625 <font class="comment">// Print stats</font>
01626 <font class="keywordflow">for</font> (smallBlock=0; smallBlock<NL_SMALLBLOCK_COUNT; smallBlock++)
01627 {
01628 uint size = (smallBlock+1)*<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s14">SmallBlockGranularity</a>;
01629 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="classNLMISC_1_1CHeapAllocator.html#a4">free</a>[smallBlock],
01630 count[smallBlock]-<a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a>[smallBlock], count[smallBlock]*(<font class="keyword">sizeof</font> (CNodeBegin) + size + NL_HEAP_NODE_END_SIZE));
01631 }
01632
01633 <font class="comment">// **************************</font>
01634
01635 <font class="comment">// Write the memory map file</font>
01636 <font class="keywordflow">if</font> (memoryMap)
01637 {
01638 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"\n\n\nHEAP LARGE BLOCK DUMP\n"</font>);
01639 fprintf (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="stringliteral">"ADDRESS, SIZE, CATEGORY, HEAP, STATE, SOURCE, LINE\n"</font>);
01640
01641 <font class="comment">// For each main block</font>
01642 currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01643 <font class="keywordflow">while</font> (currentBlock)
01644 {
01645 <font class="comment">// Get the first node</font>
01646 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01647 <font class="keywordflow">while</font> (current)
01648 {
01649 <font class="comment">// Write the entry</font>
01650 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>(CNodeBegin),
01651 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current), current->Category, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o9">_Name</a>,
01652 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (current)?<font class="stringliteral">"free"</font>:<font class="stringliteral">"used"</font>, current->File, current->Line);
01653
01654 <font class="comment">// Next node</font>
01655 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01656 }
01657
01658 <font class="comment">// Next block</font>
01659 currentBlock = currentBlock->Next;
01660 }
01661 }
01662
01663 <font class="comment">// File created successfuly</font>
01664 status = <font class="keyword">true</font>;
01665 }
01666
01667 <font class="comment">// Close</font>
01668 <font class="keywordflow">if</font> (file)
01669 fclose (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>);
01670
01671 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a35">debugPopCategoryString</a> ();
01672
01673 <font class="keywordflow">return</font> status;
01674 }
01675 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01676 <font class="preprocessor"></font>
01677 <font class="comment">// *********************************************************</font>
01678
<a name="l01679"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a17">01679</a> uint CHeapAllocator::getFreeMemory ()<font class="keyword"> const</font>
01680 <font class="keyword"></font>{
01681 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01682
01683 <font class="comment">// Sum free memory</font>
01684 uint memory = 0;
01685
01686 <font class="comment">// For each small block</font>
01687 CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01688 <font class="keywordflow">while</font> (currentSB)
01689 {
01690 <font class="comment">// For each node in this small block pool</font>
01691 uint block;
01692 <font class="keywordflow">for</font> (block=0; block<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>; block++)
01693 {
01694 <font class="comment">// Get the node</font>
01695 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01696
01697 <font class="comment">// Node allocated ?</font>
01698 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (current))
01699 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a>;
01700
01701 <font class="comment">// Next node</font>
01702 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01703 }
01704
01705 <font class="comment">// Next block</font>
01706 currentSB = currentSB->Next;
01707 }
01708
01709 <font class="comment">// For each main block</font>
01710 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01711 <font class="keywordflow">while</font> (currentBlock)
01712 {
01713 <font class="comment">// Get the first node</font>
01714 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01715 <font class="keywordflow">while</font> (current)
01716 {
01717 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01718 <font class="preprocessor"></font> <font class="comment">// Check node</font>
01719 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">checkNode</a> (current, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (current));
01720 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
01721 <font class="preprocessor"></font>
01722 <font class="comment">// Node allocated ?</font>
01723 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f8">isNodeFree</a> (current))
01724 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current) + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s1">ReleaseHeaderSize</a>;
01725
01726 <font class="comment">// Next node</font>
01727 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01728 }
01729
01730 <font class="comment">// Next block</font>
01731 currentBlock = currentBlock->Next;
01732 }
01733
01734 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01735
01736 <font class="comment">// Return memory used</font>
01737 <font class="keywordflow">return</font> memory;
01738 }
01739
01740 <font class="comment">// *********************************************************</font>
01741
<a name="l01742"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a18">01742</a> uint CHeapAllocator::getTotalMemoryUsed ()<font class="keyword"> const</font>
01743 <font class="keyword"></font>{
01744 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01745
01746 <font class="comment">// Sum total memory</font>
01747 uint memory = 0;
01748
01749 <font class="comment">// For each main block</font>
01750 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01751 <font class="keywordflow">while</font> (currentBlock)
01752 {
01753 <font class="comment">// Get block size</font>
01754 memory += currentBlock-><a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CMainBlock.html#m0">Size</a>;
01755
01756 <font class="comment">// Sum the arrays</font>
01757 memory += <font class="keyword">sizeof</font> (CMainBlock);
01758
01759 <font class="comment">// Next block</font>
01760 currentBlock = currentBlock->Next;
01761 }
01762
01763 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01764
01765 <font class="comment">// Return the memory</font>
01766 <font class="keywordflow">return</font> memory;
01767 }
01768
01769 <font class="comment">// *********************************************************</font>
01770
<a name="l01771"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a19">01771</a> uint CHeapAllocator::getSmallBlockMemory ()<font class="keyword"> const</font>
01772 <font class="keyword"></font>{
01773 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01774
01775 <font class="comment">// Sum total memory</font>
01776 uint memory = 0;
01777
01778 <font class="comment">// For each small block</font>
01779 CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01780 <font class="keywordflow">while</font> (currentSB)
01781 {
01782 <font class="comment">// Get block size</font>
01783 memory += <font class="keyword">sizeof</font>(CSmallBlockPool) + <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a> * (<font class="keyword">sizeof</font>(CNodeBegin) + currentSB->Size +
01784 NL_HEAP_NODE_END_SIZE);
01785
01786 <font class="comment">// Next block</font>
01787 currentSB = currentSB->Next;
01788 }
01789
01790 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01791
01792 <font class="comment">// Return the memory</font>
01793 <font class="keywordflow">return</font> memory;
01794 }
01795
01796 <font class="comment">// *********************************************************</font>
01797
<a name="l01798"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a21">01798</a> <font class="keywordtype">float</font> CHeapAllocator::getFragmentationRatio ()<font class="keyword"> const</font>
01799 <font class="keyword"></font>{
01800 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01801
01802 <font class="comment">// Sum free and used node</font>
01803 <font class="keywordtype">float</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a> = 0;
01804 <font class="keywordtype">float</font> used = 0;
01805
01806 <font class="comment">// For each main block</font>
01807 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01808 <font class="keywordflow">while</font> (currentBlock)
01809 {
01810 <font class="comment">// Get the first node</font>
01811 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01812 <font class="keywordflow">while</font> (current)
01813 {
01814 <font class="comment">// Node allocated ?</font>
01815 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current))
01816 used++;
01817 <font class="keywordflow">else</font>
01818 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a>++;
01819
01820 <font class="comment">// Next node</font>
01821 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01822 }
01823
01824 <font class="comment">// Next block</font>
01825 currentBlock = currentBlock->Next;
01826 }
01827
01828 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01829
01830 <font class="comment">// Return the memory</font>
01831 <font class="keywordflow">if</font> (used != 0)
01832 <font class="keywordflow">return</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a> / used;
01833 <font class="keywordflow">else</font>
01834 <font class="keywordflow">return</font> 0;
01835 }
01836
01837 <font class="comment">// *********************************************************</font>
01838
<a name="l01839"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a5">01839</a> <font class="keywordtype">void</font> CHeapAllocator::freeAll ()
01840 {
01841 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01842
01843 <font class="comment">// Sum free memory</font>
01844 uint memory = 0;
01845
01846 <font class="comment">// Clear the free tree</font>
01847 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
01848
01849 <font class="comment">// For each main block</font>
01850 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01851 <font class="keywordflow">while</font> (currentBlock)
01852 {
01853 <font class="comment">// Reinit this block</font>
01854 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c7">initEmptyBlock</a> (*currentBlock);
01855
01856 <font class="comment">// Get first block</font>
01857 CNodeBegin *node = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01858
01859 <font class="comment">// Insert the free node</font>
01860 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c3">insert</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f3">getFreeNode</a> (node));
01861
01862 <a class="code" href="include_2nel_2misc_2heap__allocator__inline_8h.html#a1">NL_UPDATE_MAGIC_NUMBER</a> (node);
01863
01864 <font class="comment">// Next block</font>
01865 currentBlock = currentBlock->Next;
01866 }
01867
01868 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01869 }
01870
01871 <font class="comment">// *********************************************************</font>
01872
<a name="l01873"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a6">01873</a> <font class="keywordtype">void</font> CHeapAllocator::releaseMemory ()
01874 {
01875 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
01876
01877 <font class="comment">// Clear the free tree</font>
01878 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a> = &<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o7">_NullNode</a>.<a class="code" href="structNLMISC_1_1CHeapAllocator_1_1CNullNode.html#m1">FreeNode</a>;
01879
01880 <font class="comment">// For each main block</font>
01881 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01882 <font class="keywordflow">while</font> (currentBlock)
01883 {
01884 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a33">freeBlock</a> (currentBlock->Ptr);
01885
01886 <font class="comment">// Next block</font>
01887 CMainBlock *toDelete = currentBlock;
01888 currentBlock = toDelete->Next;
01889 ::free (toDelete);
01890 }
01891
01892 <font class="comment">// Erase block node</font>
01893 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a> = NULL;
01894
01895 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
01896 }
01897
01898 <font class="comment">// *********************************************************</font>
01899
01900 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
01901 <font class="preprocessor"></font>
<a name="l01902"></a><a class="code" href="structNLMISC_1_1CLeak.html">01902</a> <font class="keyword">struct </font>CLeak
01903 {
<a name="l01904"></a><a class="code" href="structNLMISC_1_1CLeak.html#m0">01904</a> uint <a class="code" href="structNLMISC_1_1CLeak.html#m0">Count</a>;
<a name="l01905"></a><a class="code" href="structNLMISC_1_1CLeak.html#m1">01905</a> uint <a class="code" href="structNLMISC_1_1CLeak.html#m1">Memory</a>;
01906 };
01907
01908 <font class="keyword">typedef</font> std::map<std::string, CLeak> <a class="code" href="namespaceNLMISC.html#a194">TLinkMap</a>;
01909
<a name="l01910"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a31">01910</a> <font class="keywordtype">void</font> CHeapAllocator::debugReportMemoryLeak ()
01911 {
01912 <font class="comment">// enterCriticalSection ();</font>
01913
01914 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a34">debugPushCategoryString</a> (<a class="code" href="misc_2heap__allocator_8cpp.html#a2">NL_HEAP_MEM_DEBUG_CATEGORY</a>);
01915
01916 <font class="comment">// Sum allocated memory</font>
01917 uint memory = 0;
01918
01919 <font class="comment">// Leak map</font>
01920 <a class="code" href="namespaceNLMISC.html#a194">TLinkMap</a> leakMap;
01921
01922 <font class="comment">// Header</font>
01923 <font class="keywordtype">char</font> report[2048];
01924 <a class="code" href="namespaceNLMISC.html#a211">smprintf</a> (report, 2048, <font class="stringliteral">"Report Memory leak for allocator \"%s\"\n"</font>, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o9">_Name</a>);
01925 <a class="code" href="namespaceNLMISC.html#a296">CHeapAllocatorOutputError</a> (report);
01926
01927 <font class="comment">// For each small block</font>
01928 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
01929 <font class="keywordflow">while</font> (currentBlock)
01930 {
01931 <font class="comment">// Get the first node</font>
01932 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
01933 <font class="keywordflow">while</font> (current)
01934 {
01935 <font class="comment">// Check node</font>
01936 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">checkNode</a> (current, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (current));
01937
01938 <font class="comment">// Node allocated ?</font>
01939 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current) && ( (current->Category == NULL) || (current->Category[0] != <font class="charliteral">'_'</font>)) )
01940 {
01941 <font class="comment">// Make a report</font>
01942 <a class="code" href="namespaceNLMISC.html#a211">smprintf</a> (report, 2048, <font class="stringliteral">"%s(%d)\t: \"%s\""</font>, current->File, current->Line, current->Category);
01943
01944 <font class="comment">// Look for this leak</font>
01945 TLinkMap::iterator ite = leakMap.find (report);
01946
01947 <font class="comment">// Not found ?</font>
01948 <font class="keywordflow">if</font> (ite == leakMap.end ())
01949 {
01950 ite = leakMap.insert (TLinkMap::value_type (report, CLeak ())).first;
01951 ite->second.Count = 0;
01952 ite->second.Memory = 0;
01953 }
01954
01955 <font class="comment">// One more leak</font>
01956 ite->second.Count++;
01957 ite->second.Memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
01958
01959 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
01960 }
01961
01962 <font class="comment">// Next node</font>
01963 current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
01964 }
01965
01966 <font class="comment">// Next block</font>
01967 currentBlock = currentBlock->Next;
01968 }
01969
01970 <font class="comment">// For each small block</font>
01971 CSmallBlockPool *currentSB = (CSmallBlockPool *)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
01972 <font class="keywordflow">while</font> (currentSB)
01973 {
01974 <font class="comment">// For each node in this small block pool</font>
01975 uint block;
01976 <font class="keywordflow">for</font> (block=0; block<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>; block++)
01977 {
01978 <font class="comment">// Get the node</font>
01979 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (currentSB, block);
01980 <font class="comment">// Check node</font>
01981 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">checkNode</a> (current, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f0">evalMagicNumber</a> (current));
01982
01983 <font class="comment">// Node allocated ?</font>
01984 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#f9">isNodeUsed</a> (current) && ( (current->Category == NULL) || (current->Category[0] != <font class="charliteral">'_'</font>)) )
01985 {
01986 <font class="comment">// Make a report</font>
01987 <a class="code" href="namespaceNLMISC.html#a211">smprintf</a> (report, 2048, <font class="stringliteral">"%s(%d)\t: \"%s\""</font>, current->File, current->Line, current->Category);
01988
01989 <font class="comment">// Look for this leak</font>
01990 TLinkMap::iterator ite = leakMap.find (report);
01991
01992 <font class="comment">// Not found ?</font>
01993 <font class="keywordflow">if</font> (ite == leakMap.end ())
01994 {
01995 ite = leakMap.insert (TLinkMap::value_type (report, CLeak ())).first;
01996 ite->second.Count = 0;
01997 ite->second.Memory = 0;
01998 }
01999
02000 <font class="comment">// One more leak</font>
02001 ite->second.Count++;
02002 ite->second.Memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
02003
02004 memory += <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f7">getNodeSize</a> (current);
02005 }
02006 }
02007
02008 <font class="comment">// Next block</font>
02009 currentSB = currentSB->Next;
02010 }
02011
02012 <font class="comment">// Look for this leak</font>
02013 TLinkMap::iterator ite = leakMap.begin ();
02014 <font class="keywordflow">while</font> (ite != leakMap.end ())
02015 {
02016 <font class="comment">// Make a report</font>
02017 <a class="code" href="namespaceNLMISC.html#a211">smprintf</a> (report, 2048, <font class="stringliteral">"%s,\tLeak count : %d,\tMemory allocated : %d\n"</font>, ite->first.c_str (), ite->second.Count, ite->second.Memory);
02018
02019 <font class="comment">// Report on stderr</font>
02020 <a class="code" href="namespaceNLMISC.html#a296">CHeapAllocatorOutputError</a> (report);
02021
02022 ite++;
02023 }
02024
02025 <font class="comment">// Make a report</font>
02026 <font class="keywordflow">if</font> (memory)
02027 {
02028 <a class="code" href="namespaceNLMISC.html#a211">smprintf</a> (report, 2048, <font class="stringliteral">"%d byte(s) found\n"</font>, memory);
02029 }
02030 <font class="keywordflow">else</font>
02031 {
02032 <a class="code" href="namespaceNLMISC.html#a211">smprintf</a> (report, 2048, <font class="stringliteral">"No memory leak\n"</font>);
02033 }
02034 <a class="code" href="namespaceNLMISC.html#a296">CHeapAllocatorOutputError</a> (report);
02035
02036 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a35">debugPopCategoryString</a> ();
02037
02038 <font class="comment">// leaveCriticalSection ();</font>
02039 }
02040 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
02041 <font class="preprocessor"></font>
02042 <font class="comment">// *********************************************************</font>
02043
<a name="l02044"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a15">02044</a> <font class="keywordtype">bool</font> CHeapAllocator::checkHeap (<font class="keywordtype">bool</font> stopOnError)<font class="keyword"> const</font>
02045 <font class="keyword"></font>{
02046 <font class="keywordtype">bool</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c10">internalCheckHeap</a> (stopOnError);
02047
02048 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
02049 }
02050
02051 <font class="comment">// *********************************************************</font>
02052
<a name="l02053"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a32">02053</a> uint8 *CHeapAllocator::allocateBlock (uint size)
02054 {
02055 <font class="preprocessor">#undef malloc</font>
02056 <font class="preprocessor"></font> <font class="keywordflow">return</font> (uint8*)::malloc (size);
02057 }
02058
02059 <font class="comment">// *********************************************************</font>
02060
<a name="l02061"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a33">02061</a> <font class="keywordtype">void</font> CHeapAllocator::freeBlock (uint8 *block)
02062 {
02063 ::free (block);
02064 }
02065
02066 <font class="comment">// *********************************************************</font>
02067
<a name="l02068"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#c10">02068</a> <font class="keywordtype">bool</font> CHeapAllocator::internalCheckHeap (<font class="keywordtype">bool</font> stopOnError)<font class="keyword"> const</font>
02069 <font class="keyword"></font>{
02070 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
02071
02072 <font class="comment">// For each small blocks</font>
02073 CSmallBlockPool *pool = (CSmallBlockPool*)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o12">_SmallBlockPool</a>;
02074 <font class="keywordflow">while</font> (pool)
02075 {
02076 <font class="comment">// For each small block</font>
02077 uint smallBlock;
02078 CNodeBegin *previous = NULL;
02079 <font class="keywordflow">for</font> (smallBlock=0; smallBlock<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>; smallBlock++)
02080 {
02081 <font class="comment">// Get the small block</font>
02082 CNodeBegin *node = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (pool, smallBlock);
02083 CNodeBegin *next = (smallBlock+1<<a class="code" href="classNLMISC_1_1CHeapAllocator.html#s21s17">SmallBlockPoolSize</a>) ? <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f25">getSmallBlock</a> (pool, smallBlock+1) : NULL;
02084
02085 <font class="comment">// Check node</font>
02086 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c17">checkNodeSB</a> (pool, previous, node, next, stopOnError);
02087
02088 previous = node;
02089 }
02090
02091 <font class="comment">// Next pool</font>
02092 pool = pool->Next;
02093 }
02094
02095 <font class="comment">// For each main block</font>
02096 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
02097 <font class="keywordflow">while</font> (currentBlock)
02098 {
02099 <font class="comment">// Get the nodes</font>
02100 <font class="keyword">const</font> CNodeBegin *previous = NULL;
02101 <font class="keyword">const</font> CNodeBegin *current = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f21">getFirstNode</a> (currentBlock);
02102 <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>
02103 <font class="keyword">const</font> CNodeBegin *next;
02104
02105 <font class="comment">// For each node</font>
02106 <font class="keywordflow">while</font> (current)
02107 {
02108 <font class="comment">// Get next</font>
02109 next = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#f1">getNextNode</a> (current);
02110
02111 <font class="comment">// Return Error ?</font>
02112 <font class="keywordflow">if</font> (!<a class="code" href="classNLMISC_1_1CHeapAllocator.html#c0">checkNodeLB</a> (currentBlock, previous, current, next, stopOnError))
02113 <font class="keywordflow">return</font> <font class="keyword">false</font>;
02114
02115 <font class="comment">// Next</font>
02116 previous = current;
02117 current = next;
02118 }
02119
02120 <font class="comment">// Next block</font>
02121 currentBlock = currentBlock->Next;
02122 }
02123
02124 <font class="comment">// Check free tree</font>
02125 <font class="keywordflow">if</font> (!<a class="code" href="classNLMISC_1_1CHeapAllocator.html#c8">checkFreeNode</a> (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o6">_FreeTreeRoot</a>, stopOnError, <font class="keyword">true</font>))
02126 <font class="keywordflow">return</font> <font class="keyword">false</font>;
02127
02128 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
02129
02130 <font class="comment">// Ok, no problem</font>
02131 <font class="keywordflow">return</font> <font class="keyword">true</font>;
02132 }
02133
02134 <font class="comment">// *********************************************************</font>
02135
02136 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l02137"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a29">02137</a> <font class="preprocessor"></font><font class="keywordtype">void</font> CHeapAllocator::debugAlwaysCheckMemory (<font class="keywordtype">bool</font> alwaysCheck)
02138 {
02139 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o4">_AlwaysCheck</a> = alwaysCheck;
02140 }
02141 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
02142 <font class="preprocessor"></font>
02143 <font class="comment">// *********************************************************</font>
02144
02145 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
<a name="l02146"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a30">02146</a> <font class="preprocessor"></font><font class="keywordtype">bool</font> CHeapAllocator::debugIsAlwaysCheckMemory (<font class="keywordtype">bool</font> alwaysCheck)<font class="keyword"> const</font>
02147 <font class="keyword"></font>{
02148 <font class="keywordflow">return</font> <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o4">_AlwaysCheck</a>;
02149 }
02150 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
02151 <font class="preprocessor"></font>
02152 <font class="comment">// *********************************************************</font>
02153
<a name="l02154"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a22">02154</a> <font class="keywordtype">void</font> CHeapAllocator::setName (<font class="keyword">const</font> <font class="keywordtype">char</font>* name)
02155 {
02156 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c11">enterCriticalSection</a> ();
02157
02158 strncpy (<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o9">_Name</a>, name, <a class="code" href="classNLMISC_1_1CHeapAllocator.html#s18s8">NameLength</a>-1);
02159
02160 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#c12">leaveCriticalSection</a> ();
02161 }
02162
02163 <font class="comment">// *********************************************************</font>
02164 <font class="comment">// Category control</font>
02165 <font class="comment">// *********************************************************</font>
02166
<a name="l02167"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a34">02167</a> <font class="keywordtype">void</font> CHeapAllocator::debugPushCategoryString (<font class="keyword">const</font> <font class="keywordtype">char</font> *str)
02168 {
02169 <font class="comment">// Get the category stack pointer</font>
02170 CCategory *last = (CCategory*)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o14">_CategoryStack</a>.getPointer ();
02171
02172 <font class="comment">// New category node</font>
02173 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="misc_2heap__allocator_8cpp.html#a1">NL_HEAP_CATEGORY_BLOCK_CATEGORY</a>);
02174 _new->Name = str;
02175 _new->Next = last;
02176
02177 <font class="comment">/* Push it, no need to be thread safe here, because we use thread specifc storage */</font>
02178 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o14">_CategoryStack</a>.setPointer (_new);
02179 }
02180
02181 <font class="comment">// *********************************************************</font>
02182
<a name="l02183"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a35">02183</a> <font class="keywordtype">void</font> CHeapAllocator::debugPopCategoryString ()
02184 {
02185 <font class="comment">// Get the category stack pointer</font>
02186 CCategory *last = (CCategory*)<a class="code" href="classNLMISC_1_1CHeapAllocator.html#o14">_CategoryStack</a>.getPointer ();
02187 <font class="comment">// nlassertex (last, ("(CHeapAllocator::debugPopCategoryString ()) Pop category wihtout Push"));</font>
02188 <font class="keywordflow">if</font> (last)
02189 {
02190 CCategory *next = last->Next;
02191
02192 <font class="comment">// Free last node, no need to be thread safe here, because we use thread specifc storage</font>
02193 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#a4">free</a> (last);
02194
02195 <font class="comment">/* Push it, no need to be thread safe here, because we use thread specifc storage */</font>
02196 <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o14">_CategoryStack</a>.setPointer (next);
02197 }
02198 }
02199
02200 <font class="comment">// *********************************************************</font>
02201
02202 <font class="preprocessor">#ifndef NL_HEAP_ALLOCATION_NDEBUG</font>
02203 <font class="preprocessor"></font>
02204 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
02205 <font class="preprocessor"></font><font class="preprocessor">#pragma optimize( "", off )</font>
02206 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font>
02207 <font class="preprocessor"></font>
<a name="l02208"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#c9">02208</a> <font class="keywordtype">void</font> CHeapAllocator::checkNode (<font class="keyword">const</font> CNodeBegin *node, uint32 crc)<font class="keyword"> const</font>
02209 <font class="keyword"></font>{
02210 <font class="comment">// Check the bottom CRC of the node </font>
02211 <font class="keywordflow">if</font> (crc != *(node->EndMagicNumber))
02212 {
02213 <font class="comment">// ********</font>
02214 <font class="comment">// * STOP *</font>
02215 <font class="comment">// ********</font>
02216 <font class="comment">// * The bottom CRC32 of the current node is wrong. Use checkMemory() to debug the heap.</font>
02217 <font class="comment">// ********</font>
02218 <font class="comment">// * (*node) Check for more informations</font>
02219 <font class="comment">// ********</font>
02220 NL_ALLOC_STOP;
02221 }
02222
02223 <font class="comment">// Check the node is hold by this heap</font>
02224 <font class="keywordflow">if</font> (node->Heap != <font class="keyword">this</font>)
02225 {
02226 <font class="comment">// ********</font>
02227 <font class="comment">// * STOP *</font>
02228 <font class="comment">// ********</font>
02229 <font class="comment">// * This node is not hold by this heap. It has been allocated with another heap.</font>
02230 <font class="comment">// ********</font>
02231 <font class="comment">// * (*node) Check for more informations</font>
02232 <font class="comment">// ********</font>
02233 NL_ALLOC_STOP;
02234 }
02235 }
02236
02237 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
02238 <font class="preprocessor"></font><font class="preprocessor">#pragma optimize( "", on )</font>
02239 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font>
02240 <font class="preprocessor"></font>
02241 <font class="preprocessor">#endif // NL_HEAP_ALLOCATION_NDEBUG</font>
02242 <font class="preprocessor"></font>
02243
02244
02245
02246 <font class="preprocessor">#ifndef NL_OS_WINDOWS</font>
02247 <font class="preprocessor"></font><font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">char</font> *<a class="code" href="namespaceNLMISC.html#a298">skipWS</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *p)
02248 {
02249 <font class="keywordflow">while</font> (isspace(*p)) p++;
02250 <font class="keywordflow">return</font> (<font class="keywordtype">char</font> *)p;
02251 }
02252
02253 <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">char</font> *<a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *p)
02254 {
02255 <font class="keywordflow">while</font> (isspace(*p)) p++;
02256 <font class="keywordflow">while</font> (*p && !isspace(*p)) p++;
02257 <font class="keywordflow">return</font> (<font class="keywordtype">char</font> *)p;
02258 }
02259 <font class="preprocessor">#endif</font>
02260 <font class="preprocessor"></font>
02261 <font class="comment">// *********************************************************</font>
02262
<a name="l02263"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#d1">02263</a> uint CHeapAllocator::getAllocatedSystemMemory ()
02264 {
02265 uint systemMemory = 0;
02266 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
02267 <font class="preprocessor"></font> <font class="comment">// Get system memory informations</font>
02268 HANDLE hHeap[100];
02269 DWORD heapCount = GetProcessHeaps (100, hHeap);
02270
02271 uint heap;
02272 <font class="keywordflow">for</font> (heap = 0; heap < heapCount; heap++)
02273 {
02274 PROCESS_HEAP_ENTRY entry;
02275 entry.lpData = NULL;
02276 <font class="keywordflow">while</font> (HeapWalk (hHeap[heap], &entry))
02277 {
02278 <font class="keywordflow">if</font> (entry.wFlags & PROCESS_HEAP_ENTRY_BUSY)
02279 {
02280 systemMemory += entry.cbData + entry.cbOverhead;
02281 }
02282 }
02283 }
02284
02285 <font class="preprocessor">#elif defined NL_OS_UNIX</font>
02286 <font class="preprocessor"></font>
02287 <font class="keywordtype">char</font> buffer[4096], *p;
02288 <font class="keywordtype">int</font> fd, len;
02289
02290 fd = open(<font class="stringliteral">"/proc/self/stat"</font>, O_RDONLY);
02291 len = read(fd, buffer, <font class="keyword">sizeof</font>(buffer)-1);
02292 close(fd);
02293
02294 buffer[len] = <font class="charliteral">'\0'</font>;
02295
02296 p = buffer;
02297 p = strchr(p, <font class="charliteral">')'</font>)+1; <font class="comment">/* skip pid */</font>
02298 p = <a class="code" href="namespaceNLMISC.html#a298">skipWS</a>(p);
02299 p++;
02300
02301 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip ppid */</font>
02302 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip pgrp */</font>
02303 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip session */</font>
02304 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip tty */</font>
02305 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip tty pgrp */</font>
02306 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip flags */</font>
02307 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip min flt */</font>
02308 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip cmin flt */</font>
02309 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip maj flt */</font>
02310 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip cmaj flt */</font>
02311 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* utime */</font>
02312 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* stime */</font>
02313 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip cutime */</font>
02314 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip cstime */</font>
02315 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* priority */</font>
02316 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* nice */</font>
02317 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip timeout */</font>
02318 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip it_real_val */</font>
02319 p = <a class="code" href="namespaceNLMISC.html#a299">skipToken</a>(p); <font class="comment">/* skip start_time */</font>
02320
02321 systemMemory = strtoul(p, &p, 10); <font class="comment">/* vsize in bytes */</font>
02322
02323 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
02324 <font class="preprocessor"></font> <font class="keywordflow">return</font> systemMemory;
02325 }
02326
02327 <font class="comment">// *********************************************************</font>
02328
<a name="l02329"></a><a class="code" href="classNLMISC_1_1CHeapAllocator.html#a20">02329</a> uint CHeapAllocator::getAllocatedSystemMemoryByAllocator ()
02330 {
02331 uint nelSystemMemory = 0;
02332
02333 <font class="comment">// Build a set of allocated system memory pointers</font>
02334 std::set<void*> ptrInUse;
02335
02336 <font class="comment">// For each main block</font>
02337 CMainBlock *currentBlock = <a class="code" href="classNLMISC_1_1CHeapAllocator.html#o5">_MainBlockList</a>;
02338 <font class="keywordflow">while</font> (currentBlock)
02339 {
02340 <font class="comment">// Save pointers</font>
02341 ptrInUse.insert ((<font class="keywordtype">void</font>*)currentBlock);
02342 ptrInUse.insert ((<font class="keywordtype">void</font>*)(currentBlock->Ptr));
02343
02344 <font class="comment">// Next block</font>
02345 currentBlock = currentBlock->Next;
02346 }
02347
02348 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
02349 <font class="preprocessor"></font> <font class="comment">// Get system memory informations</font>
02350 HANDLE hHeap[100];
02351 DWORD heapCount = GetProcessHeaps (100, hHeap);
02352
02353 uint heap;
02354 <font class="keywordflow">for</font> (heap = 0; heap < heapCount; heap++)
02355 {
02356 PROCESS_HEAP_ENTRY entry;
02357 entry.lpData = NULL;
02358 <font class="keywordflow">while</font> (HeapWalk (hHeap[heap], &entry))
02359 {
02360 <font class="keywordflow">if</font> (entry.wFlags & PROCESS_HEAP_ENTRY_BUSY)
02361 {
02362 <font class="comment">// This pointer is already used ?</font>
02363 <font class="keywordflow">if</font> ( (ptrInUse.find ((<font class="keywordtype">void</font>*)((<font class="keywordtype">char</font>*)entry.lpData)) != ptrInUse.end ()) ||
02364 (ptrInUse.find ((<font class="keywordtype">void</font>*)((<font class="keywordtype">char</font>*)entry.lpData+32)) != ptrInUse.end ()) )
02365 nelSystemMemory += entry.cbData + entry.cbOverhead;
02366 }
02367 }
02368 }
02369 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
02370 <font class="preprocessor"></font> <font class="keywordflow">return</font> nelSystemMemory;
02371 }
02372
02373 <font class="comment">// *********************************************************</font>
02374
02375 } <font class="comment">// NLMISC</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|