• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
1000002 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
1100003
1200004 <span class="comment">//                     O S C L _ D E F A L L O C</span>
1300005
1400006 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
1500007
1600018 <span class="preprocessor">#ifndef OSCL_DEFALLOC_H_INCLUDED</span>
1700019 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_DEFALLOC_H_INCLUDED</span>
1800020 <span class="preprocessor"></span>
1900021 <span class="preprocessor">#ifndef OSCL_BASE_H_INCLUDED</span>
2000022 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__base_8h.html">oscl_base.h</a>"</span>
2100023 <span class="preprocessor">#endif</span>
2200024 <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>
2400026 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="osclconfig__compiler__warnings_8h.html">osclconfig_compiler_warnings.h</a>"</span>
2500027
2600028 <span class="preprocessor">#ifndef OSCL_MEM_INST_H_INCLUDED</span>
2700029 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__mem__inst_8h.html">oscl_mem_inst.h</a>"</span>
2800030 <span class="preprocessor">#endif</span>
2900031 <span class="preprocessor"></span>
3000032 <span class="comment">//A macro for using the Oscl_Alloc or Oscl_DefAlloc call with file name and</span>
3100033 <span class="comment">//line number inputs to aid memory auditing.</span>
3200034 <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>
3400036 <span class="preprocessor"></span><span class="preprocessor">#else</span>
3500037 <span class="preprocessor"></span><span class="preprocessor">#define ALLOCATE(n) allocate(n)</span>
3600038 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
3700039 <span class="preprocessor"></span>
3800040 <span class="comment">//A macro for using the Oscl_TAlloc call with file name and line number inputs</span>
3900041 <span class="comment">//to aid memory auditing.</span>
4000042 <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>
4200044 <span class="preprocessor"></span><span class="preprocessor">#else</span>
4300045 <span class="preprocessor"></span><span class="preprocessor">#define ALLOC_AND_CONSTRUCT(n) alloc_and_construct(n)</span>
4400046 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
4500047 <span class="preprocessor"></span>
4600048 <span class="comment">// This macro is defined is osclconfig_compiler_warnings.h</span>
4700049 <span class="comment">// This GCC #pragma turns off compiler warning for the rest of this header file</span>
4800050 <span class="comment">// This needs to be done because with the GCC 4.1 toolchain, many compiler warnings</span>
4900051 <span class="comment">// are generated because Oscl_Alloc and Oscl_Dealloc have virtual functions, but</span>
5000052 <span class="comment">// no virtual destructor.</span>
5100053 <span class="comment">// An attempt has been made to add the virtual destructors, however, it resulted</span>
5200054 <span class="comment">// in run time crashes indicative of double freeing of memory.</span>
5300055 <span class="comment">// This is a temporary fix, until the crashes are resolved.</span>
5400056 <span class="comment">//</span>
5500057 <span class="preprocessor">#ifdef OSCL_DISABLE_GCC_WARNING_SYSTEM_HEADER</span>
5600058 <span class="preprocessor"></span><span class="preprocessor">#pragma GCC system_header</span>
5700059 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
5800060 <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>
6000062 {
6100063     <span class="keyword">public</span>:
6200064         <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;
6300065
6400066         <span class="comment">//Allocator with file name and line number inputs to aid memory auditing.</span>
6500067         <span class="comment">//This call should be used in cases where the allocation will invoke</span>
6600068         <span class="comment">//the Oscl memory manager.</span>
6700069         <span class="comment">//A default implementation is provided for use with allocators that don't</span>
6800070         <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)
7000072         {
7100073             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(file_name);
7200074             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(line_num);
7300075             <span class="keywordflow">return</span> <a class="code" href="classOscl__Alloc.html#a0">allocate</a>(size);
7400076         }
7500077 };
7600078
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>
7800080 {
7900081     <span class="keyword">public</span>:
8000082         <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;
8100083 };
8200084
8300085
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>
8500087 {
8600088     <span class="keyword">public</span>:
8700089         <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;
8800090
8900091         <span class="comment">//Allocator with file name and line number inputs to aid memory auditing.</span>
9000092         <span class="comment">//This call should be used in cases where the allocation will invoke</span>
9100093         <span class="comment">//the Oscl memory manager.</span>
9200094         <span class="comment">//A default implementation is provided for use with allocators that don't</span>
9300095         <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)
9500097         {
9600098             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(file_name);
9700099             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(line_num);
9800100             <span class="keywordflow">return</span> <a class="code" href="classOscl__DefAlloc.html#a0">allocate</a>(size);
9900101         }
10000102         <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;
10100103 };
10200104
10300105
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>
10500107 {
10600108     <span class="keyword">public</span>:
10700109         <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;
10800110 };
10900111
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>
11100113             : <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>
11200114 {
11300115
11400116     <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>() {};
11600118 };
11700119
11800120 <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>
12000122 {
12100123     <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>;
12800130
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>() {};
13000132
13100133         <span class="comment">//this is the preferred call-- with file and line number recorded by</span>
13200134         <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)
13400136         {
13500137             <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);
13600138             <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);
13700139         }
13800140
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)
14000142         {
14100143             <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);
14200144             <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);
14300145         }
14400146
14500147         <span class="comment">//this is the preferred call-- with file and line number recorded by</span>
14600148         <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)
14800150         {
14900151             <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);
15000152             <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);
15100153             <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);
15200154         }
15300155
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)
15500157         {
15600158             <span class="comment">//note: recording file &amp; line # here is not useful-- the caller</span>
15700159             <span class="comment">//should provide them.  Just pass zero to aid debugging.</span>
15800160             <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);
15900161             <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);
16000162             <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);
16100163         }
16200164
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)
16400166         {
16500167             alloc.deallocate(p);
16600168         }
16700169
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)
16900171         {
17000172             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(n);
17100173             alloc.deallocate(p);
17200174         }
17300175
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)
17500177         {
17600178             <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));
17700179             <a class="code" href="classOscl__TAlloc.html#a5">deallocate</a>(p);
17800180         }
17900181
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)
18100183         {
18200184             <span class="keywordflow">return</span> &amp;r;
18300185         }
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>
18500187 <span class="keyword">        </span>{
18600188             <span class="keywordflow">return</span> &amp;r;
18700189         }
18800190
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)
19000192         {
19100193             <span class="keyword">new</span>(p) T(val);
19200194         }
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)
19400196         {
19500197             <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(p);
19600198             p-&gt;~T();
19700199         }
19800200
19900201         <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>
20100203         {
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>;
20300205         };
20400206
20500207     <span class="keyword">private</span>:
20600208         Alloc alloc;
20700209 };
20800210
20900211
21000214 <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