| <!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>oscl_defalloc.h Source File</title> |
| <link href="doxygen.css" rel="stylesheet" type="text/css"> |
| </head><body> |
| <!-- Generated by Doxygen 1.2.18 --> |
| <center> |
| <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> </center> |
| <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> |
| 00002 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span> |
| 00003 |
| 00004 <span class="comment">// O S C L _ D E F A L L O C</span> |
| 00005 |
| 00006 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span> |
| 00007 |
| 00018 <span class="preprocessor">#ifndef OSCL_DEFALLOC_H_INCLUDED</span> |
| 00019 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_DEFALLOC_H_INCLUDED</span> |
| 00020 <span class="preprocessor"></span> |
| 00021 <span class="preprocessor">#ifndef OSCL_BASE_H_INCLUDED</span> |
| 00022 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__base_8h.html">oscl_base.h</a>"</span> |
| 00023 <span class="preprocessor">#endif</span> |
| 00024 <span class="preprocessor"></span> |
| <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> |
| 00026 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="osclconfig__compiler__warnings_8h.html">osclconfig_compiler_warnings.h</a>"</span> |
| 00027 |
| 00028 <span class="preprocessor">#ifndef OSCL_MEM_INST_H_INCLUDED</span> |
| 00029 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__mem__inst_8h.html">oscl_mem_inst.h</a>"</span> |
| 00030 <span class="preprocessor">#endif</span> |
| 00031 <span class="preprocessor"></span> |
| 00032 <span class="comment">//A macro for using the Oscl_Alloc or Oscl_DefAlloc call with file name and</span> |
| 00033 <span class="comment">//line number inputs to aid memory auditing.</span> |
| 00034 <span class="preprocessor">#if(PVMEM_INST_LEVEL>0)</span> |
| <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> |
| 00036 <span class="preprocessor"></span><span class="preprocessor">#else</span> |
| 00037 <span class="preprocessor"></span><span class="preprocessor">#define ALLOCATE(n) allocate(n)</span> |
| 00038 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
| 00039 <span class="preprocessor"></span> |
| 00040 <span class="comment">//A macro for using the Oscl_TAlloc call with file name and line number inputs</span> |
| 00041 <span class="comment">//to aid memory auditing.</span> |
| 00042 <span class="preprocessor">#if(PVMEM_INST_LEVEL>0)</span> |
| <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> |
| 00044 <span class="preprocessor"></span><span class="preprocessor">#else</span> |
| 00045 <span class="preprocessor"></span><span class="preprocessor">#define ALLOC_AND_CONSTRUCT(n) alloc_and_construct(n)</span> |
| 00046 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
| 00047 <span class="preprocessor"></span> |
| 00048 <span class="comment">// This macro is defined is osclconfig_compiler_warnings.h</span> |
| 00049 <span class="comment">// This GCC #pragma turns off compiler warning for the rest of this header file</span> |
| 00050 <span class="comment">// This needs to be done because with the GCC 4.1 toolchain, many compiler warnings</span> |
| 00051 <span class="comment">// are generated because Oscl_Alloc and Oscl_Dealloc have virtual functions, but</span> |
| 00052 <span class="comment">// no virtual destructor.</span> |
| 00053 <span class="comment">// An attempt has been made to add the virtual destructors, however, it resulted</span> |
| 00054 <span class="comment">// in run time crashes indicative of double freeing of memory.</span> |
| 00055 <span class="comment">// This is a temporary fix, until the crashes are resolved.</span> |
| 00056 <span class="comment">//</span> |
| 00057 <span class="preprocessor">#ifdef OSCL_DISABLE_GCC_WARNING_SYSTEM_HEADER</span> |
| 00058 <span class="preprocessor"></span><span class="preprocessor">#pragma GCC system_header</span> |
| 00059 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
| 00060 <span class="preprocessor"></span> |
| <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> |
| 00062 { |
| 00063 <span class="keyword">public</span>: |
| 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; |
| 00065 |
| 00066 <span class="comment">//Allocator with file name and line number inputs to aid memory auditing.</span> |
| 00067 <span class="comment">//This call should be used in cases where the allocation will invoke</span> |
| 00068 <span class="comment">//the Oscl memory manager.</span> |
| 00069 <span class="comment">//A default implementation is provided for use with allocators that don't</span> |
| 00070 <span class="comment">//invoke Oscl memory manager.</span> |
| <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) |
| 00072 { |
| 00073 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(file_name); |
| 00074 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(line_num); |
| 00075 <span class="keywordflow">return</span> <a class="code" href="classOscl__Alloc.html#a0">allocate</a>(size); |
| 00076 } |
| 00077 }; |
| 00078 |
| <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> |
| 00080 { |
| 00081 <span class="keyword">public</span>: |
| 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; |
| 00083 }; |
| 00084 |
| 00085 |
| <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> |
| 00087 { |
| 00088 <span class="keyword">public</span>: |
| 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; |
| 00090 |
| 00091 <span class="comment">//Allocator with file name and line number inputs to aid memory auditing.</span> |
| 00092 <span class="comment">//This call should be used in cases where the allocation will invoke</span> |
| 00093 <span class="comment">//the Oscl memory manager.</span> |
| 00094 <span class="comment">//A default implementation is provided for use with allocators that don't</span> |
| 00095 <span class="comment">//invoke Oscl memory manager.</span> |
| <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) |
| 00097 { |
| 00098 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(file_name); |
| 00099 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(line_num); |
| 00100 <span class="keywordflow">return</span> <a class="code" href="classOscl__DefAlloc.html#a0">allocate</a>(size); |
| 00101 } |
| 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; |
| 00103 }; |
| 00104 |
| 00105 |
| <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> |
| 00107 { |
| 00108 <span class="keyword">public</span>: |
| 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; |
| 00110 }; |
| 00111 |
| <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> |
| 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> |
| 00114 { |
| 00115 |
| 00116 <span class="keyword">public</span>: |
| <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>() {}; |
| 00118 }; |
| 00119 |
| 00120 <span class="keyword">template</span><<span class="keyword">class</span> T, <span class="keyword">class</span> Alloc> |
| <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> |
| 00122 { |
| 00123 <span class="keyword">public</span>: |
| <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>; |
| <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>; |
| <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>; |
| <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>; |
| <a name="l00128"></a><a class="code" href="classOscl__TAlloc.html#s4">00128</a> <span class="keyword">typedef</span> T& <a class="code" href="classOscl__TAlloc.html#s4">reference</a>; |
| <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& <a class="code" href="classOscl__TAlloc.html#s5">const_reference</a>; |
| 00130 |
| <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>() {}; |
| 00132 |
| 00133 <span class="comment">//this is the preferred call-- with file and line number recorded by</span> |
| 00134 <span class="comment">//the caller. It can be invoked with the ALLOCATE macro.</span> |
| <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) |
| 00136 { |
| 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); |
| 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); |
| 00139 } |
| 00140 |
| <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) |
| 00142 { |
| 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); |
| 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); |
| 00145 } |
| 00146 |
| 00147 <span class="comment">//this is the preferred call-- with file and line number recorded by</span> |
| 00148 <span class="comment">//the caller. It can be invoked by the ALLOC_AND_CONSTRUCT macro.</span> |
| <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) |
| 00150 { |
| 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); |
| 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); |
| 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); |
| 00154 } |
| 00155 |
| <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) |
| 00157 { |
| 00158 <span class="comment">//note: recording file & line # here is not useful-- the caller</span> |
| 00159 <span class="comment">//should provide them. Just pass zero to aid debugging.</span> |
| 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); |
| 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); |
| 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); |
| 00163 } |
| 00164 |
| <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) |
| 00166 { |
| 00167 alloc.deallocate(p); |
| 00168 } |
| 00169 |
| <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) |
| 00171 { |
| 00172 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(n); |
| 00173 alloc.deallocate(p); |
| 00174 } |
| 00175 |
| <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) |
| 00177 { |
| 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)); |
| 00179 <a class="code" href="classOscl__TAlloc.html#a5">deallocate</a>(p); |
| 00180 } |
| 00181 |
| <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) |
| 00183 { |
| 00184 <span class="keywordflow">return</span> &r; |
| 00185 } |
| <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> |
| 00187 <span class="keyword"> </span>{ |
| 00188 <span class="keywordflow">return</span> &r; |
| 00189 } |
| 00190 |
| <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) |
| 00192 { |
| 00193 <span class="keyword">new</span>(p) T(val); |
| 00194 } |
| <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) |
| 00196 { |
| 00197 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(p); |
| 00198 p->~T(); |
| 00199 } |
| 00200 |
| 00201 <span class="keyword">template</span> <<span class="keyword">class</span> U, <span class="keyword">class</span> V> |
| <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> |
| 00203 { |
| <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<U, V></a> <a class="code" href="classOscl__TAlloc.html">other</a>; |
| 00205 }; |
| 00206 |
| 00207 <span class="keyword">private</span>: |
| 00208 Alloc alloc; |
| 00209 }; |
| 00210 |
| 00211 |
| 00214 <span class="preprocessor">#endif</span> |
| </pre></div><hr size="1"><img src="pvlogo_small.jpg"><address style="align: right;"><small>OSCL API</small> |
| <address style="align: left;"><small>Posting Version: OPENCORE_20090310 </small> |
| </small></address> |
| </body> |
| </html> |