Home | History | Annotate | Download | only in oscl_html
      1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
      3 <title>oscl_defalloc.h Source File</title>
      4 <link href="doxygen.css" rel="stylesheet" type="text/css">
      5 </head><body>
      6 <!-- Generated by Doxygen 1.2.18 -->
      7 <center>
      8 <a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; </center>
      9 <hr><h1>oscl_defalloc.h</h1><a href="oscl__defalloc_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">// -*- c++ -*-</span>
     10 00002 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
     11 00003 
     12 00004 <span class="comment">//                     O S C L _ D E F A L L O C</span>
     13 00005 
     14 00006 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
     15 00007 
     16 00018 <span class="preprocessor">#ifndef OSCL_DEFALLOC_H_INCLUDED</span>
     17 00019 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_DEFALLOC_H_INCLUDED</span>
     18 00020 <span class="preprocessor"></span>
     19 00021 <span class="preprocessor">#ifndef OSCL_BASE_H_INCLUDED</span>
     20 00022 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__base_8h.html">oscl_base.h</a>"</span>
     21 00023 <span class="preprocessor">#endif</span>
     22 00024 <span class="preprocessor"></span>
     23 <a name="l00025"></a><a class="code" href="group__osclbase.html#a99">00025</a> <span class="preprocessor">#define OSCL_DISABLE_WARNING_TRUNCATE_DEBUG_MESSAGE</span>
     24 00026 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="osclconfig__compiler__warnings_8h.html">osclconfig_compiler_warnings.h</a>"</span>
     25 00027 
     26 00028 <span class="preprocessor">#ifndef OSCL_MEM_INST_H_INCLUDED</span>
     27 00029 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__mem__inst_8h.html">oscl_mem_inst.h</a>"</span>
     28 00030 <span class="preprocessor">#endif</span>
     29 00031 <span class="preprocessor"></span>
     30 00032 <span class="comment">//A macro for using the Oscl_Alloc or Oscl_DefAlloc call with file name and</span>
     31 00033 <span class="comment">//line number inputs to aid memory auditing.</span>
     32 00034 <span class="preprocessor">#if(PVMEM_INST_LEVEL&gt;0)</span>
     33 <a name="l00035"></a><a class="code" href="group__osclbase.html#a100">00035</a> <span class="preprocessor"></span><span class="preprocessor">#define ALLOCATE(n) allocate_fl(n,__FILE__,__LINE__)</span>
     34 00036 <span class="preprocessor"></span><span class="preprocessor">#else</span>
     35 00037 <span class="preprocessor"></span><span class="preprocessor">#define ALLOCATE(n) allocate(n)</span>
     36 00038 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
     37 00039 <span class="preprocessor"></span>
     38 00040 <span class="comment">//A macro for using the Oscl_TAlloc call with file name and line number inputs</span>
     39 00041 <span class="comment">//to aid memory auditing.</span>
     40 00042 <span class="preprocessor">#if(PVMEM_INST_LEVEL&gt;0)</span>
     41 <a name="l00043"></a><a class="code" href="group__osclbase.html#a101">00043</a> <span class="preprocessor"></span><span class="preprocessor">#define ALLOC_AND_CONSTRUCT(n) alloc_and_construct_fl(n,__FILE__,__LINE__)</span>
     42 00044 <span class="preprocessor"></span><span class="preprocessor">#else</span>
     43 00045 <span class="preprocessor"></span><span class="preprocessor">#define ALLOC_AND_CONSTRUCT(n) alloc_and_construct(n)</span>
     44 00046 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
     45 00047 <span class="preprocessor"></span>
     46 00048 <span class="comment">// This macro is defined is osclconfig_compiler_warnings.h</span>
     47 00049 <span class="comment">// This GCC #pragma turns off compiler warning for the rest of this header file</span>
     48 00050 <span class="comment">// This needs to be done because with the GCC 4.1 toolchain, many compiler warnings</span>
     49 00051 <span class="comment">// are generated because Oscl_Alloc and Oscl_Dealloc have virtual functions, but</span>
     50 00052 <span class="comment">// no virtual destructor.</span>
     51 00053 <span class="comment">// An attempt has been made to add the virtual destructors, however, it resulted</span>
     52 00054 <span class="comment">// in run time crashes indicative of double freeing of memory.</span>
     53 00055 <span class="comment">// This is a temporary fix, until the crashes are resolved.</span>
     54 00056 <span class="comment">//</span>
     55 00057 <span class="preprocessor">#ifdef OSCL_DISABLE_GCC_WARNING_SYSTEM_HEADER</span>
     56 00058 <span class="preprocessor"></span><span class="preprocessor">#pragma GCC system_header</span>
     57 00059 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
     58 00060 <span class="preprocessor"></span>
     59 <a name="l00061"></a><a class="code" href="classOscl__Alloc.html">00061</a> <span class="keyword">class </span><a class="code" href="classOscl__Alloc.html">Oscl_Alloc</a>
     60 00062 {
     61 00063     <span class="keyword">public</span>:
     62 00064         <span class="keyword">virtual</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOscl__Alloc.html#a0">allocate</a>(<span class="keyword">const</span> uint32 size) = 0;
     63 00065 
     64 00066         <span class="comment">//Allocator with file name and line number inputs to aid memory auditing.</span>
     65 00067         <span class="comment">//This call should be used in cases where the allocation will invoke</span>
     66 00068         <span class="comment">//the Oscl memory manager.</span>
     67 00069         <span class="comment">//A default implementation is provided for use with allocators that don't</span>
     68 00070         <span class="comment">//invoke Oscl memory manager.</span>
     69 <a name="l00071"></a><a class="code" href="classOscl__Alloc.html#a1">00071</a>         <span class="keyword">virtual</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOscl__Alloc.html#a1">allocate_fl</a>(<span class="keyword">const</span> uint32 size, <span class="keyword">const</span> <span class="keywordtype">char</span> * file_name, <span class="keyword">const</span> <span class="keywordtype">int</span> line_num)
     70 00072         {
     71 00073             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(file_name);
     72 00074             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(line_num);
     73 00075             <span class="keywordflow">return</span> <a class="code" href="classOscl__Alloc.html#a0">allocate</a>(size);
     74 00076         }
     75 00077 };
     76 00078 
     77 <a name="l00079"></a><a class="code" href="classOscl__Dealloc.html">00079</a> <span class="keyword">class </span><a class="code" href="classOscl__Dealloc.html">Oscl_Dealloc</a>
     78 00080 {
     79 00081     <span class="keyword">public</span>:
     80 00082         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classOscl__Dealloc.html#a0">deallocate</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* p) = 0;
     81 00083 };
     82 00084 
     83 00085 
     84 <a name="l00086"></a><a class="code" href="classOscl__DefAlloc.html">00086</a> <span class="keyword">class </span><a class="code" href="classOscl__DefAlloc.html">Oscl_DefAlloc</a> : <span class="keyword">public</span> <a class="code" href="classOscl__Alloc.html">Oscl_Alloc</a>, <span class="keyword">public</span> <a class="code" href="classOscl__Dealloc.html">Oscl_Dealloc</a>
     85 00087 {
     86 00088     <span class="keyword">public</span>:
     87 00089         <span class="keyword">virtual</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOscl__DefAlloc.html#a0">allocate</a>(<span class="keyword">const</span> uint32 size) = 0;
     88 00090 
     89 00091         <span class="comment">//Allocator with file name and line number inputs to aid memory auditing.</span>
     90 00092         <span class="comment">//This call should be used in cases where the allocation will invoke</span>
     91 00093         <span class="comment">//the Oscl memory manager.</span>
     92 00094         <span class="comment">//A default implementation is provided for use with allocators that don't</span>
     93 00095         <span class="comment">//invoke Oscl memory manager.</span>
     94 <a name="l00096"></a><a class="code" href="classOscl__DefAlloc.html#a1">00096</a>         <span class="keyword">virtual</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOscl__DefAlloc.html#a1">allocate_fl</a>(<span class="keyword">const</span> uint32 size, <span class="keyword">const</span> <span class="keywordtype">char</span> * file_name, <span class="keyword">const</span> <span class="keywordtype">int</span> line_num)
     95 00097         {
     96 00098             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(file_name);
     97 00099             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(line_num);
     98 00100             <span class="keywordflow">return</span> <a class="code" href="classOscl__DefAlloc.html#a0">allocate</a>(size);
     99 00101         }
    100 00102         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classOscl__DefAlloc.html#a2">deallocate</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* p) = 0;
    101 00103 };
    102 00104 
    103 00105 
    104 <a name="l00106"></a><a class="code" href="classOsclDestructDealloc.html">00106</a> <span class="keyword">class </span><a class="code" href="classOsclDestructDealloc.html">OsclDestructDealloc</a>
    105 00107 {
    106 00108     <span class="keyword">public</span>:
    107 00109         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classOsclDestructDealloc.html#a0">destruct_and_dealloc</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* ptr) = 0;
    108 00110 };
    109 00111 
    110 <a name="l00112"></a><a class="code" href="classOsclAllocDestructDealloc.html">00112</a> <span class="keyword">class </span><a class="code" href="classOsclAllocDestructDealloc.html">OsclAllocDestructDealloc</a>
    111 00113             : <span class="keyword">public</span> <a class="code" href="classOsclDestructDealloc.html">OsclDestructDealloc</a>, <span class="keyword">public</span> <a class="code" href="classOscl__DefAlloc.html">Oscl_DefAlloc</a>
    112 00114 {
    113 00115 
    114 00116     <span class="keyword">public</span>:
    115 <a name="l00117"></a><a class="code" href="classOsclAllocDestructDealloc.html#a0">00117</a>         <span class="keyword">virtual</span> <a class="code" href="classOsclAllocDestructDealloc.html#a0">~OsclAllocDestructDealloc</a>() {};
    116 00118 };
    117 00119 
    118 00120 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T, <span class="keyword">class</span> Alloc&gt;
    119 <a name="l00121"></a><a class="code" href="classOscl__TAlloc.html">00121</a> <span class="keyword">class </span><a class="code" href="classOscl__TAlloc.html">Oscl_TAlloc</a> : <span class="keyword">public</span> <a class="code" href="classOsclDestructDealloc.html">OsclDestructDealloc</a>
    120 00122 {
    121 00123     <span class="keyword">public</span>:
    122 <a name="l00124"></a><a class="code" href="classOscl__TAlloc.html#s0">00124</a>         <span class="keyword">typedef</span> T           <a class="code" href="classOscl__TAlloc.html#s0">value_type</a>;
    123 <a name="l00125"></a><a class="code" href="classOscl__TAlloc.html#s1">00125</a>         <span class="keyword">typedef</span> T           * <a class="code" href="classOscl__TAlloc.html#s1">pointer</a>;
    124 <a name="l00126"></a><a class="code" href="classOscl__TAlloc.html#s2">00126</a>         <span class="keyword">typedef</span> <span class="keyword">const</span> T     * <a class="code" href="classOscl__TAlloc.html#s2">const_pointer</a>;
    125 <a name="l00127"></a><a class="code" href="classOscl__TAlloc.html#s3">00127</a>         <span class="keyword">typedef</span> uint32      <a class="code" href="classOscl__TAlloc.html#s3">size_type</a>;
    126 <a name="l00128"></a><a class="code" href="classOscl__TAlloc.html#s4">00128</a>         <span class="keyword">typedef</span> T&amp;                      <a class="code" href="classOscl__TAlloc.html#s4">reference</a>;
    127 <a name="l00129"></a><a class="code" href="classOscl__TAlloc.html#s5">00129</a>         <span class="keyword">typedef</span> <span class="keyword">const</span> T&amp;        <a class="code" href="classOscl__TAlloc.html#s5">const_reference</a>;
    128 00130 
    129 <a name="l00131"></a><a class="code" href="classOscl__TAlloc.html#a0">00131</a>         <span class="keyword">virtual</span> <a class="code" href="classOscl__TAlloc.html#a0">~Oscl_TAlloc</a>() {};
    130 00132 
    131 00133         <span class="comment">//this is the preferred call-- with file and line number recorded by</span>
    132 00134         <span class="comment">//the caller.  It can be invoked with the ALLOCATE macro.</span>
    133 <a name="l00135"></a><a class="code" href="classOscl__TAlloc.html#a1">00135</a>         <a class="code" href="classOscl__TAlloc.html#s1">pointer</a> <a class="code" href="classOscl__TAlloc.html#a1">allocate_fl</a>(uint32 size , <span class="keyword">const</span> <span class="keywordtype">char</span> * file_name, <span class="keyword">const</span> <span class="keywordtype">int</span> line_num)
    134 00136         {
    135 00137             <a class="code" href="group__osclbase.html#a25">OsclAny</a>* tmp = alloc.allocate_fl(size * <span class="keyword">sizeof</span>(<a class="code" href="classOscl__TAlloc.html#s0">value_type</a>), file_name, line_num);
    136 00138             <span class="keywordflow">return</span> <a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a>, tmp);
    137 00139         }
    138 00140 
    139 <a name="l00141"></a><a class="code" href="classOscl__TAlloc.html#a2">00141</a>         <a class="code" href="classOscl__TAlloc.html#s1">pointer</a> <a class="code" href="classOscl__TAlloc.html#a2">allocate</a>(uint32 size)
    140 00142         {
    141 00143             <a class="code" href="group__osclbase.html#a25">OsclAny</a>* tmp = alloc.allocate_fl(size * <span class="keyword">sizeof</span>(<a class="code" href="classOscl__TAlloc.html#s0">value_type</a>), <a class="code" href="group__osclbase.html#a81">NULL</a>, 0);
    142 00144             <span class="keywordflow">return</span> <a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a>, tmp);
    143 00145         }
    144 00146 
    145 00147         <span class="comment">//this is the preferred call-- with file and line number recorded by</span>
    146 00148         <span class="comment">//the caller.  It can be invoked by the ALLOC_AND_CONSTRUCT macro.</span>
    147 <a name="l00149"></a><a class="code" href="classOscl__TAlloc.html#a3">00149</a>         <a class="code" href="classOscl__TAlloc.html#s1">pointer</a> <a class="code" href="classOscl__TAlloc.html#a3">alloc_and_construct_fl</a>(<a class="code" href="classOscl__TAlloc.html#s5">const_reference</a> val, <span class="keyword">const</span> <span class="keywordtype">char</span> * file_name, <span class="keyword">const</span> <span class="keywordtype">int</span> line_num)
    148 00150         {
    149 00151             <a class="code" href="group__osclbase.html#a25">OsclAny</a>* tmp = alloc.allocate_fl(<span class="keyword">sizeof</span>(<a class="code" href="classOscl__TAlloc.html#s0">value_type</a>), file_name, line_num);
    150 00152             <a class="code" href="classOscl__TAlloc.html#a10">construct</a>(<a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a>, tmp), val);
    151 00153             <span class="keywordflow">return</span> <a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a>, tmp);
    152 00154         }
    153 00155 
    154 <a name="l00156"></a><a class="code" href="classOscl__TAlloc.html#a4">00156</a>         <a class="code" href="classOscl__TAlloc.html#s1">pointer</a> <a class="code" href="classOscl__TAlloc.html#a4">alloc_and_construct</a>(<a class="code" href="classOscl__TAlloc.html#s5">const_reference</a> val)
    155 00157         {
    156 00158             <span class="comment">//note: recording file &amp; line # here is not useful-- the caller</span>
    157 00159             <span class="comment">//should provide them.  Just pass zero to aid debugging.</span>
    158 00160             <a class="code" href="group__osclbase.html#a25">OsclAny</a>* tmp = alloc.allocate_fl(<span class="keyword">sizeof</span>(<a class="code" href="classOscl__TAlloc.html#s0">value_type</a>), <a class="code" href="group__osclbase.html#a81">NULL</a>, 0);
    159 00161             <a class="code" href="classOscl__TAlloc.html#a10">construct</a>(<a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a>, tmp), val);
    160 00162             <span class="keywordflow">return</span> <a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a>, tmp);
    161 00163         }
    162 00164 
    163 <a name="l00165"></a><a class="code" href="classOscl__TAlloc.html#a5">00165</a>         <span class="keywordtype">void</span> <a class="code" href="classOscl__TAlloc.html#a5">deallocate</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* p)
    164 00166         {
    165 00167             alloc.deallocate(p);
    166 00168         }
    167 00169 
    168 <a name="l00170"></a><a class="code" href="classOscl__TAlloc.html#a6">00170</a>         <span class="keywordtype">void</span> <a class="code" href="classOscl__TAlloc.html#a5">deallocate</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* p, <a class="code" href="classOscl__TAlloc.html#s3">size_type</a> n)
    169 00171         {
    170 00172             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(n);
    171 00173             alloc.deallocate(p);
    172 00174         }
    173 00175 
    174 <a name="l00176"></a><a class="code" href="classOscl__TAlloc.html#a7">00176</a>         <span class="keywordtype">void</span> <a class="code" href="classOscl__TAlloc.html#a7">destruct_and_dealloc</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* p)
    175 00177         {
    176 00178             <a class="code" href="classOscl__TAlloc.html#a11">destroy</a>(<a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a>, p));
    177 00179             <a class="code" href="classOscl__TAlloc.html#a5">deallocate</a>(p);
    178 00180         }
    179 00181 
    180 <a name="l00182"></a><a class="code" href="classOscl__TAlloc.html#a8">00182</a>         <a class="code" href="classOscl__TAlloc.html#s1">pointer</a> <a class="code" href="classOscl__TAlloc.html#a8">address</a>(<a class="code" href="classOscl__TAlloc.html#s4">reference</a> r)
    181 00183         {
    182 00184             <span class="keywordflow">return</span> &amp;r;
    183 00185         }
    184 <a name="l00186"></a><a class="code" href="classOscl__TAlloc.html#a9">00186</a>         <a class="code" href="classOscl__TAlloc.html#s2">const_pointer</a> <a class="code" href="classOscl__TAlloc.html#a8">address</a>(<a class="code" href="classOscl__TAlloc.html#s5">const_reference</a> r)<span class="keyword"> const</span>
    185 00187 <span class="keyword">        </span>{
    186 00188             <span class="keywordflow">return</span> &amp;r;
    187 00189         }
    188 00190 
    189 <a name="l00191"></a><a class="code" href="classOscl__TAlloc.html#a10">00191</a>         <span class="keywordtype">void</span> <a class="code" href="classOscl__TAlloc.html#a10">construct</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a> p, <a class="code" href="classOscl__TAlloc.html#s5">const_reference</a> val)
    190 00192         {
    191 00193             <span class="keyword">new</span>(p) T(val);
    192 00194         }
    193 <a name="l00195"></a><a class="code" href="classOscl__TAlloc.html#a11">00195</a>         <span class="keywordtype">void</span> <a class="code" href="classOscl__TAlloc.html#a11">destroy</a>(<a class="code" href="classOscl__TAlloc.html#s1">pointer</a> p)
    194 00196         {
    195 00197             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(p);
    196 00198             p-&gt;~T();
    197 00199         }
    198 00200 
    199 00201         <span class="keyword">template</span> &lt;<span class="keyword">class</span> U, <span class="keyword">class</span> V&gt;
    200 <a name="l00202"></a><a class="code" href="structOscl__TAlloc_1_1rebind.html">00202</a>         <span class="keyword">struct </span><a class="code" href="structOscl__TAlloc_1_1rebind.html">rebind</a>
    201 00203         {
    202 <a name="l00204"></a><a class="code" href="structOscl__TAlloc_1_1rebind.html#s0">00204</a>             <span class="keyword">typedef</span> <a class="code" href="classOscl__TAlloc.html">Oscl_TAlloc&lt;U, V&gt;</a> <a class="code" href="classOscl__TAlloc.html">other</a>;
    203 00205         };
    204 00206 
    205 00207     <span class="keyword">private</span>:
    206 00208         Alloc alloc;
    207 00209 };
    208 00210 
    209 00211 
    210 00214 <span class="preprocessor">#endif</span>
    211 </pre></div><hr size="1"><img src="pvlogo_small.jpg"><address style="align: right;"><small>OSCL API</small>
    212 <address style="align: left;"><small>Posting Version: OPENCORE_20090310 </small>
    213 </small></address>
    214 </body>
    215 </html>
    216