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