![]()
geRam
Description: Replacement for malloc, realloc and free
Source file: …\genesis3d\OpenSource\Source\Support\RAM.h
Functions:
AddAllocation, Allocate, AllocateClear, EnableCriticalCallback, Free_, Realloc, ReportAllocations, SetCriticalCallbackMacro:
GE_RAM_ALLOCATE_ARRAY, GE_RAM_ALLOCATE_STRUCT, GE_RAM_REALLOC_ARRAYTypes:
geRam_CriticalCallbackFunctionChanges for Genesis3D v1.6:
None![]()
Macros:
(type, count);This is a convenience macro that calls geRam_Allocate to allocate ram for an array of count size of type items. A pointer is returned to the allocated memory and is pre-cast to the correct type.
Returns: a pointer to the allocated memory, orNULL on failure.
Return to Contents
(type);
This is a convenience macro that calls geRam_Allocate to allocate ram for a structure of type type and pre-casts the returned pointer to type.
Returns: a pointer to the allocated memory orNULL on failure.
Return to Contents
(ptr,type,count);
This is a convenience macro that calls geRam_Realloc to adjust the memory pool to accomodate an array of count items of type type at the address ptr.
Returns: a pre-cast ptr to the allocated memory.
Return to Contents
![]()
Types:
geRam_CriticalCallbackFunction
This is the type of a callback function that can be set using geRam_SetCriticalCallback() to be called when geRam_Allocate is unable to allocate the requested memory.
typedefint (*geRam_CriticalCallbackFunction)( void);
Return to Contents
![]()
Functions:
![]()
GENESISAPI void geRam_AddAllocation(int n, uint32 size);
This function can be used by programs that use some other memory allocation method but would like to let geRam keep track of statistics of memory usage. n is the number of allocations to add (or subtract) and size is the amount of memory to add (or subtract).
Returns: nothing.
Return to Contents
![]()
GENESISAPI void * geRam_Allocate(uint32 size);
This function allocates the size bytes of memory an returns a pointer to it.
Returns: a pointer to the allocated memory,NULL on error.
Notes:
Return to Contents
![]()
GENESISAPI void * geRam_AllocateClear(uint32 size);
This function allocates size bytes of memory, clears it to 0 and returns a pointer to it.
Returns: a pointer to the allocated memory, orNULL on failure.
Notes:
Return to Contents
![]()
GENESISAPI int geRam_EnableCriticalCallback(int add);
This function increments an internal counter by add (which may be negative). If the internal counter is greater than 0 and a critical callback function has been set with geRamSetCriticalCallback(), then that function is called if a memory allocation request fails.
Returns: the current counter value after add is applied.
Notes:
Return to Contents
![]()
GENESISAPI void geRam_Free_( void * ptr);
This function releases memory previously allocated at* ptr.
Returns: nothing.
Notes:
Return to Contents
![]()
geBoolean geRam_IsValidPtr(void * ptr);
This function tests whether ptr is a valid non-NULL pointer using information created by geRam_Allocate. This function is only available in debug builds.
Returns:GE_TRUE if ptr is valid, GE_FALSE otherwise.
Return to Contents
![]()
GENESISAPI void * geRam_Realloc(void * ptr, uint32 newsize);
This function adjusts the size of a previously allocated block of memory at ptr to newsize. If ptr isNULL, a new memory block is allocated.
Returns: A pointer to the adjusted memory pool, orNULL on failure.
Notes:
Return to Contents
![]()
GENESISAPI void geRam_ReportAllocations(void);
This function can be called just before exitting to report on any non-freed memory to aid in detecting memory leaks. This function is only available in debug builds (I think).
Returns: nothing.
Return to Contents
![]()
GENESISAPI geRam_CriticalCallbackFunction geRam_SetCriticalCallback(geRam_CriticalCallbackFunction callback);
This function is used to set the critical callback function that will be called if geRam_Allocate() is unable to allocate the requested memory.
Returns: a ptr to the set callback function.
Notes:
Return to Contents
![]()