Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bad97183153701b09df5fae1052b1c30 > files > 52

crystalspace-doc-1.2.1-5mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Crystal Space 1.2.1: csutil/blockallocator.h Source File (Crystal Space 1.2.1 Public API Reference)</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="head">
 <tr height="59">
  <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td>
  <td class="head"><h2>Public API Reference</h2></td>
 </tr>
 <tr height="11">
  <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td>
 </tr>
</table>
<div class="content">
<!-- Generated by Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="namespaces.html"><span>Namespaces</span></a></li>
    <li><a href="classes.html"><span>Classes</span></a></li>
    <li class="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<h1>csutil/blockallocator.h</h1><a href="blockallocator_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">  Crystal Space Generic Object Block Allocator</span>
<a name="l00003"></a>00003 <span class="comment">  Copyright (C) 2005 by Eric Sunshine &lt;sunshine@sunshineco.com&gt;</span>
<a name="l00004"></a>00004 <span class="comment">            (C) 2006 by Frank Richter</span>
<a name="l00005"></a>00005 <span class="comment"></span>
<a name="l00006"></a>00006 <span class="comment">  This library is free software; you can redistribute it and/or</span>
<a name="l00007"></a>00007 <span class="comment">  modify it under the terms of the GNU Library General Public</span>
<a name="l00008"></a>00008 <span class="comment">  License as published by the Free Software Foundation; either</span>
<a name="l00009"></a>00009 <span class="comment">  version 2 of the License, or (at your option) any later version.</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment">  This library is distributed in the hope that it will be useful,</span>
<a name="l00012"></a>00012 <span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00013"></a>00013 <span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<a name="l00014"></a>00014 <span class="comment">  Library General Public License for more details.</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment">  You should have received a copy of the GNU Library General Public</span>
<a name="l00017"></a>00017 <span class="comment">  License along with this library; if not, write to the Free</span>
<a name="l00018"></a>00018 <span class="comment">  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span>
<a name="l00019"></a>00019 <span class="comment">*/</span>
<a name="l00020"></a>00020 <span class="preprocessor">#ifndef __CSUTIL_BLOCKALLOCATOR_H__</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#define __CSUTIL_BLOCKALLOCATOR_H__</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="fixedsizeallocator_8h.html" title="Fixed Size Block Allocator.">csutil/fixedsizeallocator.h</a>"</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="custom__new__disable_8h.html" title="Include file to disable CrystalSpace&amp;#39;s &amp;#39;operator new&amp;#39; override, which...">csutil/custom_new_disable.h</a>"</span>
<a name="l00030"></a>00030 
<a name="l00037"></a>00037 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;
<a name="l00038"></a><a class="code" href="classcsBlockAllocatorDisposeDelete.html">00038</a> <span class="keyword">class </span><a class="code" href="classcsBlockAllocatorDisposeDelete.html" title="Block allocator disposal mixin that just destructs an instance.">csBlockAllocatorDisposeDelete</a>
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 <span class="keyword">public</span>:
<a name="l00044"></a>00044   <span class="keyword">template</span>&lt;<span class="keyword">typename</span> BA&gt;
<a name="l00045"></a><a class="code" href="classcsBlockAllocatorDisposeDelete.html#3562fdaea42dcc9c1b6c33d6fbcb72f4">00045</a>   <a class="code" href="classcsBlockAllocatorDisposeDelete.html#3562fdaea42dcc9c1b6c33d6fbcb72f4" title="Construct with a given block allocator.">csBlockAllocatorDisposeDelete</a> (<span class="keyword">const</span> BA&amp;, <span class="keywordtype">bool</span> legit)
<a name="l00046"></a>00046   { (void)legit; }
<a name="l00048"></a><a class="code" href="classcsBlockAllocatorDisposeDelete.html#127823d07f561ccf368a3fa8fef1d71b">00048</a>   <span class="keywordtype">void</span> <a class="code" href="classcsBlockAllocatorDisposeDelete.html#127823d07f561ccf368a3fa8fef1d71b" title="Destructs the object.">Dispose</a> (<span class="keywordtype">void</span>* p) 
<a name="l00049"></a>00049   {
<a name="l00050"></a>00050     ((T*)p)-&gt;~T();
<a name="l00051"></a>00051   }
<a name="l00052"></a>00052 };
<a name="l00053"></a>00053 
<a name="l00058"></a>00058 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;
<a name="l00059"></a><a class="code" href="classcsBlockAllocatorDisposeLeaky.html">00059</a> <span class="keyword">class </span><a class="code" href="classcsBlockAllocatorDisposeLeaky.html" title="Block allocator disposal mixin that destructs, unless upon final cleanup, where a...">csBlockAllocatorDisposeLeaky</a>
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061   <span class="keywordtype">bool</span> doWarn;
<a name="l00062"></a>00062 <span class="preprocessor">#ifdef CS_DEBUG</span>
<a name="l00063"></a>00063 <span class="preprocessor"></span>  <span class="keyword">const</span> <span class="keywordtype">char</span>* parentClass;
<a name="l00064"></a>00064   <span class="keyword">const</span> <span class="keywordtype">void</span>* parent;
<a name="l00065"></a>00065   <span class="keywordtype">size_t</span> count;
<a name="l00066"></a>00066 <span class="preprocessor">#endif</span>
<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="keyword">public</span>:
<a name="l00068"></a>00068 <span class="preprocessor">#ifdef CS_DEBUG</span>
<a name="l00069"></a>00069 <span class="preprocessor"></span>
<a name="l00076"></a>00076   <span class="keyword">template</span>&lt;<span class="keyword">typename</span> BA&gt;
<a name="l00077"></a>00077   <a class="code" href="classcsBlockAllocatorDisposeLeaky.html#9540112306c41808ee22e727f904c8fb">csBlockAllocatorDisposeLeaky</a> (<span class="keyword">const</span> BA&amp; ba, <span class="keywordtype">bool</span> legit) :
<a name="l00078"></a>00078     doWarn (!legit), parentClass (<span class="keyword">typeid</span>(BA).name()), parent (&amp;ba),
<a name="l00079"></a>00079     count (0)
<a name="l00080"></a>00080   { 
<a name="l00081"></a>00081   }
<a name="l00082"></a>00082 <span class="preprocessor">#else</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span>  <span class="keyword">template</span>&lt;<span class="keyword">typename</span> BA&gt;
<a name="l00084"></a><a class="code" href="classcsBlockAllocatorDisposeLeaky.html#9540112306c41808ee22e727f904c8fb">00084</a>   <a class="code" href="classcsBlockAllocatorDisposeLeaky.html#9540112306c41808ee22e727f904c8fb">csBlockAllocatorDisposeLeaky</a> (<span class="keyword">const</span> BA&amp;, <span class="keywordtype">bool</span> legit) : doWarn (!legit)
<a name="l00085"></a>00085   { }
<a name="l00086"></a>00086 <span class="preprocessor">#endif</span>
<a name="l00087"></a><a class="code" href="classcsBlockAllocatorDisposeLeaky.html#6e51f7be751ff889589d3bf70499351c">00087</a> <span class="preprocessor"></span>  <a class="code" href="classcsBlockAllocatorDisposeLeaky.html#6e51f7be751ff889589d3bf70499351c">~csBlockAllocatorDisposeLeaky</a>()
<a name="l00088"></a>00088   {
<a name="l00089"></a>00089 <span class="preprocessor">#ifdef CS_DEBUG</span>
<a name="l00090"></a>00090 <span class="preprocessor"></span>    <span class="keywordflow">if</span> ((count &gt; 0) &amp;&amp; doWarn)
<a name="l00091"></a>00091     {
<a name="l00092"></a>00092       <a class="code" href="group__util.html#g9bd60492f7f494e915605a6cbc42a54b" title="CS version of fprintf (stderr, str, .">csPrintfErr</a>(<span class="stringliteral">"%s %p leaked %zu objects.\n"</span>, parentClass, (<span class="keywordtype">void</span>*)<span class="keyword">this</span>, 
<a name="l00093"></a>00093         count);
<a name="l00094"></a>00094     }
<a name="l00095"></a>00095 <span class="preprocessor">#endif</span>
<a name="l00096"></a>00096 <span class="preprocessor"></span>  }
<a name="l00098"></a><a class="code" href="classcsBlockAllocatorDisposeLeaky.html#13b2420db4b18eb7676a56d09f9d1c8b">00098</a>   <span class="keywordtype">void</span> <a class="code" href="classcsBlockAllocatorDisposeLeaky.html#13b2420db4b18eb7676a56d09f9d1c8b" title="Destructs the object, unless in auto-cleanup.">Dispose</a> (<span class="keywordtype">void</span>* p) 
<a name="l00099"></a>00099   {
<a name="l00100"></a>00100     <span class="keywordflow">if</span> (!doWarn) ((T*)p)-&gt;~T();
<a name="l00101"></a>00101 <span class="preprocessor">#ifdef CS_DEBUG</span>
<a name="l00102"></a>00102 <span class="preprocessor"></span>    count++;
<a name="l00103"></a>00103 <span class="preprocessor">#endif</span>
<a name="l00104"></a>00104 <span class="preprocessor"></span>  }
<a name="l00105"></a>00105 };
<a name="l00106"></a>00106 
<a name="l00127"></a>00127 <span class="keyword">template</span> &lt;<span class="keyword">class </span>T,
<a name="l00128"></a>00128   <span class="keyword">class </span>Allocator = <a class="code" href="classCS_1_1Memory_1_1AllocatorMalloc.html" title="A default memory allocator that allocates with cs_malloc().">CS::Memory::AllocatorMalloc</a>, 
<a name="l00129"></a>00129   <span class="keyword">class </span>ObjectDispose = <a class="code" href="classcsBlockAllocatorDisposeDelete.html" title="Block allocator disposal mixin that just destructs an instance.">csBlockAllocatorDisposeDelete&lt;T&gt;</a> &gt;
<a name="l00130"></a><a class="code" href="classcsBlockAllocator.html">00130</a> <span class="keyword">class </span><a class="code" href="classcsBlockAllocator.html" title="This class implements a memory allocator which can efficiently allocate objects that...">csBlockAllocator</a> : <span class="keyword">public</span> <a class="code" href="classcsFixedSizeAllocator.html" title="This class implements a memory allocator which can efficiently allocate objects that...">csFixedSizeAllocator</a>&lt;sizeof (T), Allocator&gt;
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132 <span class="keyword">public</span>:
<a name="l00133"></a><a class="code" href="classcsBlockAllocator.html#4710c6bd2ffbf296353a3fd9953cc221">00133</a>   <span class="keyword">typedef</span> <a class="code" href="classcsBlockAllocator.html" title="This class implements a memory allocator which can efficiently allocate objects that...">csBlockAllocator&lt;T, Allocator&gt;</a> <a class="code" href="classcsBlockAllocator.html">ThisType</a>;
<a name="l00134"></a><a class="code" href="classcsBlockAllocator.html#35eed981347bb115e554e8dc6142aa11">00134</a>   <span class="keyword">typedef</span> T <a class="code" href="classcsBlockAllocator.html#35eed981347bb115e554e8dc6142aa11">ValueType</a>;
<a name="l00135"></a><a class="code" href="classcsBlockAllocator.html#1d9fba4c4fe8f5f6504c0953b879026d">00135</a>   <span class="keyword">typedef</span> Allocator <a class="code" href="classCS_1_1Memory_1_1AllocatorAlign.html" title="This class implements an allocator policy which aligns the first element on given...">AllocatorType</a>;
<a name="l00136"></a>00136 
<a name="l00137"></a>00137 <span class="keyword">protected</span>:
<a name="l00138"></a><a class="code" href="classcsBlockAllocator.html#5f246f5d86f2b83531ed5b7e09562618">00138</a>   <span class="keyword">typedef</span> <a class="code" href="classcsFixedSizeAllocator.html" title="This class implements a memory allocator which can efficiently allocate objects that...">csFixedSizeAllocator&lt;sizeof (T), Allocator&gt;</a> <a class="code" href="classcsFixedSizeAllocator.html">superclass</a>;
<a name="l00139"></a>00139 <span class="keyword">private</span>:
<a name="l00140"></a>00140   <span class="keywordtype">void</span>* <a class="code" href="classcsBlockAllocator.html#2fda57e30eb28fd3cec4ac33322e0daa" title="Allocate a new object.">Alloc</a> (<span class="keywordtype">size_t</span> <span class="comment">/*n*/</span>) { <span class="keywordflow">return</span> 0; }                       <span class="comment">// Illegal</span>
<a name="l00141"></a>00141   <span class="keywordtype">void</span>* <a class="code" href="classcsBlockAllocator.html#2fda57e30eb28fd3cec4ac33322e0daa" title="Allocate a new object.">Alloc</a> (<span class="keywordtype">void</span>* <span class="comment">/*p*/</span>, <span class="keywordtype">size_t</span> <span class="comment">/*newSize*/</span>) { <span class="keywordflow">return</span> 0; }   <span class="comment">// Illegal</span>
<a name="l00142"></a>00142   <span class="keywordtype">void</span> SetMemTrackerInfo (<span class="keyword">const</span> <span class="keywordtype">char</span>* <span class="comment">/*info*/</span>) { }             <span class="comment">// Illegal</span>
<a name="l00143"></a>00143 <span class="keyword">public</span>:
<a name="l00163"></a><a class="code" href="classcsBlockAllocator.html#d8f422778b7c2fa33ee76c77f409b0c3">00163</a>   <a class="code" href="classcsBlockAllocator.html#d8f422778b7c2fa33ee76c77f409b0c3" title="Construct a new block allocator.">csBlockAllocator</a>(<span class="keywordtype">size_t</span> nelem = 32) : <a class="code" href="classcsFixedSizeAllocator.html">superclass</a> (nelem)
<a name="l00164"></a>00164   {
<a name="l00165"></a>00165   }
<a name="l00166"></a>00166 
<a name="l00170"></a><a class="code" href="classcsBlockAllocator.html#6d21fa52f4c7bb6c4ebf469b8882aee8">00170</a>   <a class="code" href="classcsBlockAllocator.html#6d21fa52f4c7bb6c4ebf469b8882aee8" title="Destroy all allocated objects and release memory.">~csBlockAllocator</a>()
<a name="l00171"></a>00171   {
<a name="l00172"></a>00172     ObjectDispose dispose (*<span class="keyword">this</span>, <span class="keyword">false</span>);
<a name="l00173"></a>00173     <a class="code" href="classcsFixedSizeAllocator.html#2d6916d415daaa8d83aeccbf922b010a" title="Destroys all living objects and releases all memory allocated by the pool.">DisposeAll</a> (dispose);
<a name="l00174"></a>00174   }
<a name="l00175"></a>00175 
<a name="l00181"></a><a class="code" href="classcsBlockAllocator.html#799b3de443ebd5b4fc807c08dc64404d">00181</a>   <span class="keywordtype">void</span> <a class="code" href="classcsBlockAllocator.html#799b3de443ebd5b4fc807c08dc64404d" title="Destroy all objects allocated by the pool.">Empty</a>()
<a name="l00182"></a>00182   {
<a name="l00183"></a>00183     ObjectDispose dispose (*<span class="keyword">this</span>, <span class="keyword">true</span>);
<a name="l00184"></a>00184     <a class="code" href="classcsFixedSizeAllocator.html#2d6916d415daaa8d83aeccbf922b010a" title="Destroys all living objects and releases all memory allocated by the pool.">DisposeAll</a> (dispose);
<a name="l00185"></a>00185   }
<a name="l00186"></a>00186 
<a name="l00191"></a><a class="code" href="classcsBlockAllocator.html#2fda57e30eb28fd3cec4ac33322e0daa">00191</a>   T* <a class="code" href="classcsBlockAllocator.html#2fda57e30eb28fd3cec4ac33322e0daa" title="Allocate a new object.">Alloc</a> ()
<a name="l00192"></a>00192   {
<a name="l00193"></a>00193     <span class="keywordflow">return</span> <span class="keyword">new</span> (<a class="code" href="classcsFixedSizeAllocator.html#a23579349fa21fff8f1fa6dc30f5f427" title="Allocate a chunk of memory.">superclass::Alloc</a>()) T;
<a name="l00194"></a>00194   }
<a name="l00195"></a>00195 
<a name="l00200"></a><a class="code" href="classcsBlockAllocator.html#4d331c017f7173bc4f6922dd72eb1535">00200</a>   <span class="keywordtype">void</span> <a class="code" href="classcsBlockAllocator.html#4d331c017f7173bc4f6922dd72eb1535" title="Deallocate an object.">Free</a> (T* p)
<a name="l00201"></a>00201   {
<a name="l00202"></a>00202     ObjectDispose dispose (*<span class="keyword">this</span>, <span class="keyword">true</span>);
<a name="l00203"></a>00203     <a class="code" href="classcsFixedSizeAllocator.html#69cb1c8ff50f68d5779b180bd32de2c6" title="Deallocate a chunk of memory.">superclass::Free</a> (dispose, p);
<a name="l00204"></a>00204   }
<a name="l00210"></a><a class="code" href="classcsBlockAllocator.html#06bc80b173329739a612e43ef6257e53">00210</a>   <span class="keywordtype">bool</span> <a class="code" href="classcsBlockAllocator.html#06bc80b173329739a612e43ef6257e53" title="Try to delete an object.">TryFree</a> (T* p)
<a name="l00211"></a>00211   {
<a name="l00212"></a>00212     ObjectDispose dispose (*<span class="keyword">this</span>, <span class="keyword">true</span>);
<a name="l00213"></a>00213     <span class="keywordflow">return</span> <a class="code" href="classcsFixedSizeAllocator.html#eae28b243f7ec94c18f88cd028289b54" title="Try to delete a chunk of memory.">superclass::TryFree</a> (dispose, p);
<a name="l00214"></a>00214   }
<a name="l00215"></a>00215 };
<a name="l00216"></a>00216 
<a name="l00219"></a>00219 <span class="preprocessor">#include "<a class="code" href="custom__new__enable_8h.html" title="Include file to re-enable CrystalSpace&amp;#39;s &amp;#39;operator new&amp;#39; override after...">csutil/custom_new_enable.h</a>"</span>
<a name="l00220"></a>00220 
<a name="l00221"></a>00221 <span class="preprocessor">#endif // __CSUTIL_BLOCKALLOCATOR_H__</span>
</pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by 
<a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 
</small></address> </div></body> </html>