diff options
author | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
commit | 0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch) | |
tree | 2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /docs/doxygen/nel/misc_2heap__allocator_8cpp-source.html | |
download | nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip |
Initial commit
Diffstat (limited to 'docs/doxygen/nel/misc_2heap__allocator_8cpp-source.html')
-rw-r--r-- | docs/doxygen/nel/misc_2heap__allocator_8cpp-source.html | 2444 |
1 files changed, 2444 insertions, 0 deletions
diff --git a/docs/doxygen/nel/misc_2heap__allocator_8cpp-source.html b/docs/doxygen/nel/misc_2heap__allocator_8cpp-source.html new file mode 100644 index 00000000..084e0487 --- /dev/null +++ b/docs/doxygen/nel/misc_2heap__allocator_8cpp-source.html @@ -0,0 +1,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> |