/*========================================================================= * * GENMEM.H - 29 March 1999, Dave Humphrey (uesp@m0use.net) * *=======================================================================*/ #ifndef __GENMEM_H #define __GENMEM_H /* System dependant required includes */ #if defined(__DJGPP__) #include <dpmi.h> #endif /* System independant required includes */ #include <malloc.h> /*========================================================================= * * Begin Defines * *=======================================================================*/ /* Program Identification */ #define GENMEM_NAME "GENMEM.CPP" #define GENMEM_VERSION "0.3b" #define GENMEM_AUTHOR "Dave Humphrey (uesp@m0use.net)" #define GENMEM_DATE "29 March 1999" /* Release a handle type object (windows) */ #ifndef RELEASE #define RELEASE(Obj) { if ((Obj) != NULL) { (Obj)->Release(); (Obj) = NULL; } } #endif /* Shortcut for creating a general pointer */ #define CreatePointer(ptr, type) { \ (ptr) = new type; \ if ((ptr) == NULL) { \ ErrorHandler.SetExtError(ERR_MEM, __FILE__, __FUNC__, __LINE__); \ ErrorHandler.Exit("Failed to allocate %u bytes in file %s, function %s, line #%d!", sizeof(type), __FILE__, __FUNC__, __LINE__); \ } \ } /* Shortcut for creating a general pointerarray */ #define CreatePointerArray(ptr, type, number) { \ (ptr) = new type[number]; \ if ((ptr) == NULL) { \ ErrorHandler.SetExtError(ERR_MEM, __FILE__, __FUNC__, __LINE__); \ ErrorHandler.Exit("Failed to allocate %u bytes (%u[%u]) in file %s, function %s, line #%d!", sizeof(type)*number, sizeof(type), number, __FILE__, __FUNC__, __LINE__); \ } \ } /* Shortcut for destroying a pointer and setting it to NULL */ #define DestroyPointer(ptr) { \ if ((ptr) != NULL) { \ delete ptr; ptr = NULL; } \ } #define DestroyPointerArray(ptr) { \ if ((ptr) != NULL) { \ delete[] ptr; ptr = NULL; } \ } /* Return values for the GetMemory...() type functions */ #define GET_MEMORY_ERROR (-1) #define GET_MEMORY_NOTDEFINED (-2) /* Return values for the GetHeapStatus() function */ #define _HEAPNOTDEFINED (-10) #ifndef _WIN32 #define _HEAPBADBEGIN (-3) #define _HEAPBADNODE (-4) #define _HEAPBADPTR (-6) #else #define _HEAPCORRUPT (-7) #endif /* Macros used to simulate old, removed functions and macros */ #define DESTROY(ptr) DestroyPointer(ptr) #define create_ptr(t) CreateString(t) /*========================================================================= * End of Defines *=======================================================================*/ /*========================================================================= * * Begin Forward Function/Procedure Declarations * *=======================================================================*/ /* Attempts to allocate and initialize a string pointer */ char *CreateString (const char *pString); char *CreateString (const size_t l); /* Returns the amount of memory available */ long GetFreeMemory (void); /* Returns the Total Amount of Memory on System */ long GetTotalMemory (void); /* Returns the amount of memory currently allocated */ long GetUsedMemory (void); /* Returns the status of the heap */ int GetHeapStatus (void); /* Returns a string based on the status of the Heap */ char *GetHeapStatusString (void); /*========================================================================= * End of Forward Function/Procedure Declarations *=======================================================================*/ #endif /*========================================================================= * End of File GENMEM.H *=======================================================================*/