00001 #ifndef MEMORYH
00002 #define MEMORYH
00003
00024 void *MNewPtr(int size);
00025
00027 void MFreePtr(void *ptr);
00028
00029
00030
00031
00032
00033
00034
00035
00044 void MSetAllocFailFunction(void (*AllocFail)(int allocationSize));
00045
00046 #include "sysdefines.h"
00047
00048 #define DEBUGMEMORY
00049
00050
00051 void *__MAllocPtrWrapper(int size);
00052 void **__MAllocHandleWrapper(int size);
00053
00054
00055 #if defined(UNIX) | defined(CYGNUS) | defined(WIN32)
00056 #define __SystemNewPtr(size) malloc(size)
00057 #define __SystemFreePtr(ptr) free(ptr)
00058
00059 #define __SystemNewHandle(size) __MMakeHandle(size)
00060 #define __SystemFreeHandle(handle) (__MFreeHandle((void **)handle))
00061
00062 void **__MMakeHandle(long size);
00063 void __MFreeHandle(void **handle);
00064
00065 #define __SystemLockHandle(handle) (*handle)
00066 #define __SystemUnlockHandle(handle) {}
00067
00068 #define __SystemMoveMemory(dst, src, bytes) memmove(dst, src, bytes)
00069
00070 #elif defined(PILOT)
00071 #define __SystemNewPtr(size) MemPtrNew(size)
00072 #define __SystemFreePtr(ptr) MemPtrFree(ptr)
00073
00074 #define __SystemNewHandle(size) MemHandleNew(size)
00075 #define __SystemFreeHandle(handle) MemHandleFree(handle)
00076
00077 #define __SystemLockHandle(handle) MemHandleLock(handle)
00078 #define __SystemUnlockHandle(handle) MemHandleUnlock(handle)
00079
00080 #define __SystemMoveMemory(dst, src, bytes) MemMove(dst, src, bytes)
00081 #endif
00082
00083 #ifdef DEBUGMEMORY
00084 void *_MDebugNewPtr(long size);
00085
00086
00087
00088 void _MDebugFreePtr(void *ptr);
00089 void **_MDebugNewHandle(long size);
00090 void _MDebugFreeHandle(void **handle);
00091 void *_MDebugLockHandle(void **handle);
00092 void _MDebugUnlockHandle(void **handle);
00093
00095 long MGetTotalAllocation(void);
00096
00105 void MSetActivePool(int poolID);
00106
00115 int MGetActivePool(void);
00116
00126 long MGetPoolAllocation(int poolID);
00127
00133 void MMovePtrToPool(void *ptr, int poolID);
00134
00135 #define MNewPtr(size) _MDebugNewPtr(size)
00136 #define MFreePtr(ptr) _MDebugFreePtr(ptr)
00137
00138 #define MNewHandle(size) __SystemNewHandle(size)
00139 #define MFreeHandle(handle) __SystemFreeHandle(handle)
00140
00141 #define MLockHandle(handle) __SystemLockHandle(handle)
00142 #define MUnlockHandle(handle) __SystemUnlockHandle(handle)
00143
00145 #define MMemMove(dst, src, bytes) __SystemMoveMemory(dst, src, bytes)
00146
00147 #else
00148 #define MGetTotalAllocation() (0)
00149 #define MSetActivePool(poolID) (0)
00150 #define MGetActivePool() (0)
00151 #define MGetPoolAllocation(poolID) (0)
00152 #define MMovePtrToPool(ptr, poolID) (0)
00153
00154 #define MNewPtr(size) __MAllocPtrWrapper(size)
00155 #define MFreePtr(ptr) __SystemFreePtr(ptr)
00156
00157 #define MNewHandle(size) __MAllocHandleWrapper(size)
00158 #define MFreeHandle(handle) __SystemFreeHandle(handle)
00159
00160 #define MLockHandle(handle) __SystemLockHandle(handle)
00161 #define MUnlockHandle(handle) __SystemUnlockHandle(handle)
00162 #define MMemMove(dst, src, bytes) __SystemMoveMemory(dst, src, bytes)
00163 #endif
00164
00165 #endif