00001 #if 1
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef RC_MEMORY_H
00010 #define RC_MEMORY_H
00011
00012
00013
00014 #ifndef RC_MEMORY_DEBUG
00015
00016
00017 void *MemoryAllocate(
00018 const u32 mem_size
00019 );
00020
00021 void *MemoryAllocateSetZero(
00022 const u32 n,
00023 const u32 type_size
00024 );
00025
00026 void MemoryFree(
00027 void *ptr
00028 );
00029
00030 void *MemoryReallocate(
00031 void *old_ptr,
00032 const u32 new_size
00033 );
00034
00035 #endif
00036
00037
00038 void *operator new(
00039 size_t mem_size
00040 );
00041
00042 void *operator new [](
00043 size_t mem_size
00044 );
00045
00046 void operator delete(
00047 void *ptr
00048 );
00049
00050 void operator delete [](
00051 void *ptr
00052 );
00053
00054 #ifdef RC_MEMORY_DEBUG
00055
00056
00057 void *MemoryAllocateDebug(
00058 u32 mem_size,
00059 const char *file,
00060 const char *func,
00061 int line
00062 );
00063
00064 void *MemoryAllocateSetZeroDebug(
00065 u32 n,
00066 u32 type_size,
00067 const char *file,
00068 const char *func,
00069 int line
00070 );
00071
00072 void MemoryFreeDebug(
00073 void *ptr
00074 );
00075
00076 void *MemoryReallocateDebug(
00077 void *old_ptr,
00078 u32 new_size,
00079 const char *file,
00080 const char *func,
00081 int line
00082 );
00083
00084 i32 MemorySetInfo(
00085 const char *new_file,
00086 const char *new_func,
00087 i32 new_line
00088 );
00089
00090 #endif
00091
00092 #ifdef malloc
00093 #undef malloc
00094 #endif
00095
00096 #ifdef calloc
00097 #undef calloc
00098 #endif
00099
00100 #ifdef free
00101 #undef free
00102 #endif
00103
00104 #ifdef realloc
00105 #undef realloc
00106 #endif
00107
00108 #ifdef new
00109 #undef new
00110 #endif
00111
00112 #ifdef delete
00113 #undef delete
00114 #endif
00115
00116
00117 #ifdef RC_MEMORY_DEBUG
00118
00119 #define malloc(mem_size) MemoryAllocateDebug(mem_size, __FILE__, __FUNCTION__, __LINE__)
00120 #define calloc(n, type_size) MemoryAllocateSetZeroDebug(n, type_size, __FILE__, __FUNCTION__, __LINE__)
00121 #define free(ptr) MemoryFreeDebug(ptr)
00122 #define realloc(old_ptr, new_size) MemoryReallocateDebug(old_ptr, new_size, __FILE__, __FUNCTION__, __LINE__)
00123
00124 #define new (MemorySetInfo(__FILE__, __FUNCTION__, __LINE__)) ? 0 : new
00125
00126 #else
00127
00128 #define malloc(mem_size) MemoryAllocate(mem_size)
00129 #define calloc(n, mem_size) MemoryAllocateSetZero(n, type_size)
00130 #define free(ptr) MemoryFree(ptr)
00131 #define realloc(old_ptr, new_size) MemoryReallocate(old_ptr, new_size)
00132
00133 #endif
00134
00135
00136
00138 u32 getAllocationSize();
00139
00141 u32 getAllocationPeak();
00142
00143
00145 u32 getAllocationPeakLocal();
00146
00148 u32 getCurrentAllocationCount();
00149
00151 u32 getAllocationCount();
00152
00154 u32 getDeallocationCount();
00155
00157 u32 getReallocationCount();
00158
00160 void logAllocations();
00161
00166 void ensure_heap();
00167
00168
00169 void MemoryRegisterCommands();
00170
00171 #endif
00172
00173 #else
00174
00175 #ifndef RC_MEMORY_H
00176 #define RC_MEMORY_H
00177
00178 u32 getAllocationSize();
00179
00180 u32 getAllocationPeak();
00181
00182 u32 getAllocationPeakLocal();
00183
00184 u32 getCurrentAllocationCount();
00185
00186 u32 getAllocationCount();
00187
00188 u32 getDeallocationCount();
00189
00190 u32 getReallocationCount();
00191
00192 void logAllocations();
00193
00194 void ensure_heap();
00195
00196 #endif
00197
00198 #endif
00199