📄 object_8h-source.html
字号:
00957 00965 <span class="keyword">static</span> <span class="keywordtype">void</span> DumpObjectsSince(00966 DWORD objectNumber 00967 );00968 00974 <span class="keyword">static</span> <span class="keywordtype">void</span> DumpObjectsSince(00975 DWORD objectNumber, 00976 ostream & strm 00977 );00978 00984 <span class="keyword">static</span> <span class="keywordtype">void</span> SetAllocationBreakpoint(00985 DWORD point 00986 );00987 00988 <span class="keyword">protected</span>:00989 <span class="keywordtype">void</span> * InternalAllocate(00990 size_t nSize, <span class="comment">// Number of bytes to allocate.</span>00991 <span class="keyword">const</span> <span class="keywordtype">char</span> * file, <span class="comment">// Source file name for allocating function.</span>00992 <span class="keywordtype">int</span> line, <span class="comment">// Source file line for allocating function.</span>00993 <span class="keyword">const</span> <span class="keywordtype">char</span> * className <span class="comment">// Class name for allocating function.</span>00994 );00995 Validation InternalValidate(00996 <span class="keywordtype">void</span> * ptr, <span class="comment">// Pointer to memory block to check</span>00997 <span class="keyword">const</span> <span class="keywordtype">char</span> * className, <span class="comment">// Class name it should be.</span>00998 ostream * error <span class="comment">// Stream to receive error message (may be NULL)</span>00999 );01000 <span class="keywordtype">void</span> InternalDumpStatistics(ostream & strm);01001 <span class="keywordtype">void</span> InternalDumpObjectsSince(DWORD objectNumber, ostream & strm);01002 01003 <span class="keyword">class </span>Wrapper {01004 <span class="keyword">public</span>:01005 Wrapper();01006 ~Wrapper();01007 PMemoryHeap * operator->()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> instance; }01008 <span class="keyword">private</span>:01009 PMemoryHeap * instance;01010 };01011 <span class="keyword">friend</span> <span class="keyword">class </span>Wrapper;01012 01013 <span class="keyword">enum</span> Flags {01014 NoLeakPrint = 101015 };01016 01017 <span class="preprocessor">#pragma pack(1)</span>01018 <span class="preprocessor"></span> <span class="keyword">struct </span>Header {01019 <span class="keyword">enum</span> {01020 <span class="comment">// Assure that the Header struct is aligned to 8 byte boundary</span>01021 NumGuardBytes = 16 - (<span class="keyword">sizeof</span>(Header *) +01022 <span class="keyword">sizeof</span>(Header *) +01023 <span class="keyword">sizeof</span>(<span class="keyword">const</span> <span class="keywordtype">char</span> *) +01024 <span class="keyword">sizeof</span>(<span class="keyword">const</span> <span class="keywordtype">char</span> *) +01025 <span class="keyword">sizeof</span>(size_t) +01026 <span class="keyword">sizeof</span>(DWORD) +01027 <span class="keyword">sizeof</span>(WORD) +01028 <span class="keyword">sizeof</span>(BYTE))%801029 };01030 01031 Header * prev;01032 Header * next;01033 <span class="keyword">const</span> <span class="keywordtype">char</span> * className;01034 <span class="keyword">const</span> <span class="keywordtype">char</span> * fileName;01035 size_t size;01036 DWORD request;01037 WORD line;01038 BYTE flags;01039 <span class="keywordtype">char</span> guard[NumGuardBytes];01040 01041 <span class="keyword">static</span> <span class="keywordtype">char</span> GuardBytes[NumGuardBytes];01042 };01043 <span class="preprocessor">#pragma pack()</span>01044 <span class="preprocessor"></span>01045 BOOL isDestroyed;01046 01047 Header * listHead;01048 Header * listTail;01049 01050 <span class="keyword">static</span> DWORD allocationBreakpoint;01051 DWORD allocationRequest;01052 DWORD firstRealObject;01053 BYTE flags;01054 01055 <span class="keywordtype">char</span> allocFillChar;01056 <span class="keywordtype">char</span> freeFillChar;01057 01058 DWORD currentMemoryUsage;01059 DWORD peakMemoryUsage;01060 DWORD currentObjects;01061 DWORD peakObjects;01062 DWORD totalObjects;01063 01064 ostream * leakDumpStream;01065 01066 <span class="preprocessor">#if defined(_WIN32)</span>01067 <span class="preprocessor"></span> CRITICAL_SECTION mutex;01068 <span class="preprocessor">#elif defined(P_PTHREADS)</span>01069 <span class="preprocessor"></span> pthread_mutex_t mutex;01070 <span class="preprocessor">#elif defined(P_VXWORKS)</span>01071 <span class="preprocessor"></span> <span class="keywordtype">void</span> * mutex;01072 <span class="preprocessor">#endif</span>01073 <span class="preprocessor"></span>};01074 01075 01080 <span class="keyword">inline</span> <span class="keywordtype">void</span> * <a class="code" href="object_8h.html#a20">runtime_malloc</a>(size_t bytes ) { <span class="keywordflow">return</span> malloc(bytes); }01081 01086 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="object_8h.html#a21">runtime_free</a>(<span class="keywordtype">void</span> * ptr ) { free(ptr); }01087 01088 01095 <span class="preprocessor">#define malloc(s) PMemoryHeap::Allocate(s, __FILE__, __LINE__, NULL)</span>01096 <span class="preprocessor"></span>01103 <span class="preprocessor">#define calloc(n,s) PMemoryHeap::Allocate(n, s, __FILE__, __LINE__)</span>01104 <span class="preprocessor"></span>01111 <span class="preprocessor">#define realloc(p,s) PMemoryHeap::Reallocate(p, s, __FILE__, __LINE__)</span>01112 <span class="preprocessor"></span>01113 01120 <span class="preprocessor">#define free(p) PMemoryHeap::Deallocate(p, NULL)</span>01121 <span class="preprocessor"></span>01122 01129 <span class="preprocessor">#define cfree(p) PMemoryHeap::Deallocate(p, NULL)</span>01130 <span class="preprocessor"></span>01131 01146 <span class="preprocessor">#define PNEW new (__FILE__, __LINE__)</span>01147 <span class="preprocessor"></span>01148 <span class="preprocessor">#if !defined(_MSC_VER) || _MSC_VER<1200</span>01149 <span class="preprocessor"></span><span class="preprocessor">#define PSPECIAL_DELETE_FUNCTION</span>01150 <span class="preprocessor"></span><span class="preprocessor">#else</span>01151 <span class="preprocessor"></span><span class="preprocessor">#define PSPECIAL_DELETE_FUNCTION \</span>01152 <span class="preprocessor"> void operator delete(void * ptr, const char *, int) \</span>01153 <span class="preprocessor"> { PMemoryHeap::Deallocate(ptr, Class()); } \</span>01154 <span class="preprocessor"> void operator delete[](void * ptr, const char *, int) \</span>01155 <span class="preprocessor"> { PMemoryHeap::Deallocate(ptr, Class()); }</span>01156 <span class="preprocessor"></span><span class="preprocessor">#endif</span>01157 <span class="preprocessor"></span>01158 <span class="preprocessor">#define PNEW_AND_DELETE_FUNCTIONS \</span>01159 <span class="preprocessor"> void * operator new(size_t nSize, const char * file, int line) \</span>01160 <span class="preprocessor"> { return PMemoryHeap::Allocate(nSize, file, line, Class()); } \</span>01161 <span class="preprocessor"> void * operator new(size_t nSize) \</span>01162 <span class="preprocessor"> { return PMemoryHeap::Allocate(nSize, NULL, 0, Class()); } \</span>01163 <span class="preprocessor"> void operator delete(void * ptr) \</span>01164 <span class="preprocessor"> { PMemoryHeap::Deallocate(ptr, Class()); } \</span>01165 <span class="preprocessor"> void * operator new[](size_t nSize, const char * file, int line) \</span>01166 <span class="preprocessor"> { return PMemoryHeap::Allocate(nSize, file, line, Class()); } \</span>01167 <span class="preprocessor"> void * operator new[](size_t nSize) \</span>01168 <span class="preprocessor"> { return PMemoryHeap::Allocate(nSize, NULL, 0, Class()); } \</span>01169 <span class="preprocessor"> void operator delete[](void * ptr) \</span>01170 <span class="preprocessor"> { PMemoryHeap::Deallocate(ptr, Class()); } \</span>01171 <span class="preprocessor"> PSPECIAL_DELETE_FUNCTION</span>01172 <span class="preprocessor"></span>01173 01174 <span class="keyword">inline</span> <span class="keywordtype">void</span> * <a class="code" href="object_8h.html#a62">operator new</a>(size_t nSize, <span class="keyword">const</span> <span class="keywordtype">char</span> * file, <span class="keywordtype">int</span> line)01175 { <span class="keywordflow">return</span> PMemoryHeap::Allocate(nSize, file, line, NULL); }01176 01177 <span class="keyword">inline</span> <span class="keywordtype">void</span> * <a class="code" href="object_8h.html#a63">operator new[]</a>(size_t nSize, <span class="keyword">const</span> <span class="keywordtype">char</span> * file, <span class="keywordtype">int</span> line)01178 { <span class="keywordflow">return</span> PMemoryHeap::Allocate(nSize, file, line, NULL); }01179 01180 <span class="preprocessor">#ifndef __GNUC__</span>01181 <span class="preprocessor"></span><span class="keywordtype">void</span> * <a class="code" href="object_8h.html#a62">operator new</a>(size_t nSize);01182 <span class="keywordtype">void</span> * <a class="code" href="object_8h.html#a63">operator new[]</a>(size_t nSize);01183 01184 <span class="keywordtype">void</span> <a class="code" href="object_8h.html#a64">operator delete</a>(<span class="keywordtype">void</span> * ptr);01185 <span class="keywordtype">void</span> <a class="code" href="object_8h.html#a65">operator delete[]</a>(<span class="keywordtype">void</span> * ptr);01186 01187 <span class="preprocessor">#if defined(_MSC_VER) && _MSC_VER>=1200</span>01188 <span class="preprocessor"></span><span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="object_8h.html#a64">operator delete</a>(<span class="keywordtype">void</span> * ptr, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">int</span>)01189 { PMemoryHeap::Deallocate(ptr, NULL); }01190 01191 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="object_8h.html#a65">operator delete[]</a>(<span class="keywordtype">void</span> * ptr, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">int</span>)01192 { PMemoryHeap::Deallocate(ptr, NULL); }01193 <span class="preprocessor">#endif</span>01194 <span class="preprocessor"></span><span class="preprocessor">#endif</span>01195 <span class="preprocessor"></span>01196 01197 <span class="preprocessor">#else // PMEMORY_CHECK</span>01198 <span class="preprocessor"></span><a name="l01199"></a><a class="code" href="object_8h.html#a18">01199</a> <span class="preprocessor">#define PNEW new</span>01200 <span class="preprocessor"></span>01201 <span class="p
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -