--- /dev/null
+/****************************************************************************************/\r
+/* RAM.H */\r
+/* */\r
+/* Author: */\r
+/* Description: Replacement for malloc, realloc and free */\r
+/* */\r
+/* The contents of this file are subject to the Genesis3D Public License */\r
+/* Version 1.01 (the "License"); you may not use this file except in */\r
+/* compliance with the License. You may obtain a copy of the License at */\r
+/* http://www.genesis3d.com */\r
+/* */\r
+/* Software distributed under the License is distributed on an "AS IS" */\r
+/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */\r
+/* the License for the specific language governing rights and limitations */\r
+/* under the License. */\r
+/* */\r
+/* The Original Code is Genesis3D, released March 25, 1999. */\r
+/* Genesis3D Version 1.1 released November 15, 1999 */\r
+/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */\r
+/* */\r
+/****************************************************************************************/\r
+#ifndef GE_RAM_H\r
+#define GE_RAM_H\r
+\r
+#include "BaseType.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef int (* geRam_CriticalCallbackFunction)(void);\r
+\r
+/*\r
+ Set the critical callback function. ram_allocate will call the critical\r
+ callback function if it's unable to allocate memory.\r
+*/\r
+GENESISAPI geRam_CriticalCallbackFunction geRam_SetCriticalCallback\r
+ (\r
+ geRam_CriticalCallbackFunction callback\r
+ );\r
+\r
+/*\r
+ increments or decrements a counter . if the counter is >0\r
+ the critical callback function (if set) is called for a failed memory allocation.\r
+ add is added to the current counter value. the new counter value is returned.\r
+*/\r
+GENESISAPI int geRam_EnableCriticalCallback(int add);\r
+\r
+\r
+/*\r
+ Allocate memory of the given size. In debug mode, the memory is filled\r
+ with 0xA5, and we keep track of the amount of memory allocated. Also, in debug\r
+ mode, we track where the memory was allocated and can optionally provide a\r
+ report of allocated blocks. See geRam_ReportAllocations.\r
+*/\r
+#ifndef NDEBUG\r
+\r
+#define geRam_Allocate(size) _geRam_DebugAllocate(size, __FILE__, __LINE__)\r
+\r
+// Do not call _geRam_DebugAllocate directly.\r
+GENESISAPI void* _geRam_DebugAllocate(uint32 size, const char* pFile, int line);\r
+\r
+#else\r
+\r
+GENESISAPI void *geRam_Allocate(uint32 size);\r
+\r
+#endif\r
+\r
+/*\r
+ Free an allocated memory block.\r
+*/\r
+GENESISAPI void geRam_Free_(void *ptr);\r
+\r
+ extern void *StupidUnusedPointer; // never used, except to mask the\r
+ // possible warning you get if you use the geRam_Free macro below, without\r
+ // using the xxx pointer again in the same block. This is ugly.\r
+ \r
+#define geRam_Free(xxx) geRam_Free_(xxx) ,(xxx)=NULL, StupidUnusedPointer=(xxx)\r
+\r
+/*\r
+ Reallocate memory. This function supports shrinking and expanding blocks,\r
+ and will also act like ram_allocate if the pointer passed to it is NULL.\r
+ It won't, however, free the memory if you pass it a 0 size.\r
+*/\r
+#ifndef NDEBUG\r
+\r
+#define geRam_Realloc(ptr, newsize) _geRam_DebugRealloc(ptr, newsize, __FILE__, __LINE__)\r
+\r
+// Do not call _geRam_DebugRealloc directly.\r
+GENESISAPI void* _geRam_DebugRealloc(void* ptr, uint32 size, const char* pFile, int line);\r
+\r
+#else\r
+\r
+GENESISAPI void *geRam_Realloc(void *ptr,uint32 newsize);\r
+\r
+#endif\r
+\r
+#ifndef NDEBUG\r
+\r
+GENESISAPI void geRam_ReportAllocations(void);\r
+\r
+#else\r
+\r
+#define geRam_ReportAllocations() \r
+\r
+#endif\r
+\r
+#ifndef NDEBUG\r
+ extern int32 geRam_CurrentlyUsed;\r
+ extern int32 geRam_NumberOfAllocations;\r
+ extern int32 geRam_MaximumUsed;\r
+ extern int32 geRam_MaximumNumberOfAllocations;\r
+\r
+GENESISAPI void geRam_AddAllocation(int n,uint32 size);\r
+#else\r
+ #define geRam_AddAllocation(n,s)\r
+#endif\r
+\r
+// allocate the ram & clear it. (calloc)\r
+GENESISAPI void * geRam_AllocateClear(uint32 size);\r
+\r
+#define GE_RAM_ALLOCATE_STRUCT(type) (type *)geRam_Allocate (sizeof (type))\r
+#define GE_RAM_ALLOCATE_ARRAY(type,count) (type *)geRam_Allocate (sizeof (type) * (count))\r
+\r
+#ifndef NDEBUG\r
+#define GE_RAM_REALLOC_ARRAY(ptr,type,count) (type *)geRam_Realloc( (ptr), sizeof(type) * (count) );{type *XX=(ptr);}\r
+#else\r
+#define GE_RAM_REALLOC_ARRAY(ptr,type,count) (type *)geRam_Realloc( (ptr), sizeof(type) * (count) )\r
+#endif\r
+\r
+#ifndef NDEBUG\r
+geBoolean geRam_IsValidPtr(void *ptr);\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+ }\r
+#endif\r
+\r
+#endif\r
+\r