Wm4Memory.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WM4MEMORY_H
00018 #define WM4MEMORY_H
00019
00020 #ifndef WM4_MEMORY_MANAGER
00021
00022
00023 #define WM4_NEW new
00024 #define WM4_DELETE delete
00025
00026 #else
00027
00028
00029
00030
00031
00032 #include "Wm4FoundationLIB.h"
00033 #include "Wm4Platforms.h"
00034
00035 namespace Wm4
00036 {
00037
00038 class WM4_FOUNDATION_ITEM Memory
00039 {
00040 public:
00041
00042
00043 struct Block
00044 {
00045 size_t Size;
00046 const char* File;
00047 unsigned int Line;
00048 bool IsArray;
00049 Block* Prev;
00050 Block* Next;
00051 };
00052
00053
00054 static size_t& MaxAllowedBytes ();
00055 static bool& TrackSizes ();
00056
00057
00058 static size_t GetNumNewCalls ();
00059 static size_t GetNumDeleteCalls ();
00060 static size_t GetNumBlocks ();
00061 static size_t GetNumBytes ();
00062 static size_t GetMaxAllocatedBytes ();
00063 static size_t GetMaxBlockSize ();
00064 static size_t GetHistogram (int i);
00065
00066
00067 static const Block* GetHead ();
00068 static const Block* GetTail ();
00069
00070
00071 static void GenerateReport (const char* acFilename);
00072
00073 private:
00074
00075
00076 static size_t ms_uiNumNewCalls;
00077 static size_t ms_uiNumDeleteCalls;
00078
00079
00080
00081
00082
00083 static size_t ms_uiMaxAllowedBytes;
00084
00085
00086 static size_t ms_uiNumBlocks;
00087
00088
00089 static size_t ms_uiNumBytes;
00090
00091
00092 static Block* ms_pkHead;
00093 static Block* ms_pkTail;
00094
00095
00096
00097 static bool ms_bTrackSizes;
00098
00099
00100 static size_t ms_uiMaxAllocatedBytes;
00101
00102
00103 static size_t ms_uiMaxBlockSize;
00104
00105
00106
00107
00108
00109
00110
00111 static size_t ms_auiHistogram[32];
00112
00113
00114 public:
00115 static void* Allocate (size_t uiSize, char* acFile, unsigned int uiLine,
00116 bool bIsArray);
00117 static void Deallocate (char* pcAddr, bool bIsArray);
00118 static void InsertBlock (Block* pkBlock);
00119 static void RemoveBlock (Block* pkBlock);
00120 };
00121
00122 }
00123
00124 #include "Wm4Memory.inl"
00125
00126 #define WM4_NEW new(__FILE__,__LINE__)
00127 #define WM4_DELETE delete
00128
00129 void* operator new (size_t uiSize);
00130 void* operator new[](size_t uiSize);
00131 void* operator new (size_t uiSize, char* acFile, unsigned int uiLine);
00132 void* operator new[] (size_t uiSize, char* acFile, unsigned int uiLine);
00133 void operator delete (void* pvAddr);
00134 void operator delete[] (void* pvAddr);
00135 void operator delete (void* pvAddr, char* acFile, unsigned int uiLine);
00136 void operator delete[] (void* pvAddr, char* acFile, unsigned int uiLine);
00137
00138 #endif
00139 #endif