Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

RAM.H File Reference

#include "basetype.h"

Go to the source code of this file.

Defines

#define geRam_Allocate(size)   _geRam_DebugAllocate(size, __FILE__, __LINE__)
#define geRam_Free(xxx)   geRam_Free_(xxx) ,(xxx)=NULL, StupidUnusedPointer=(xxx)
#define geRam_Realloc(ptr, newsize)   _geRam_DebugRealloc(ptr, newsize, __FILE__, __LINE__)
#define GE_RAM_ALLOCATE_STRUCT(type)   (type *)geRam_Allocate (sizeof (type))
#define GE_RAM_ALLOCATE_ARRAY(type, count)   (type *)geRam_Allocate (sizeof (type) * (count))
#define GE_RAM_REALLOC_ARRAY(ptr, type, count)   (type *)geRam_Realloc( (ptr), sizeof(type) * (count) );{type *XX=(ptr);}

Typedefs

typedef int(* geRam_CriticalCallbackFunction )(void)

Functions

GENESISAPI geRam_CriticalCallbackFunction geRam_SetCriticalCallback (geRam_CriticalCallbackFunction callback)
GENESISAPI int geRam_EnableCriticalCallback (int add)
GENESISAPI void * _geRam_DebugAllocate (uint32 size, const char *pFile, int line)
GENESISAPI void geRam_Free_ (void *ptr)
GENESISAPI void * _geRam_DebugRealloc (void *ptr, uint32 size, const char *pFile, int line)
GENESISAPI void geRam_ReportAllocations (void)
GENESISAPI void geRam_AddAllocation (int n, uint32 size)
GENESISAPI void * geRam_AllocateClear (uint32 size)
geBoolean geRam_IsValidPtr (void *ptr)

Variables

void * StupidUnusedPointer
int32 geRam_CurrentlyUsed
int32 geRam_NumberOfAllocations
int32 geRam_MaximumUsed
int32 geRam_MaximumNumberOfAllocations


Define Documentation

#define GE_RAM_ALLOCATE_ARRAY type,
count   )     (type *)geRam_Allocate (sizeof (type) * (count))
 

Definition at line 123 of file RAM.H.

Referenced by ElectricFx_InitBitmap(), geActor_DefCreateFromFile(), geBodyInst_GetGeometryPrep(), geEntity_EntitySetLoadEntities(), geFont_AddCharacters(), geFont_DrawUsingDIB(), gePuppet_FetchTextures(), geWBitmap_Pool_CreateAllWBitmaps(), geWorld_Create(), geXFArray_Create(), ParseClassData(), ReadChunk(), Smoke_InitBitmap(), StackInit(), Surf_WorldInit(), Vis_WorldInit(), Water_Create(), and World_CreateBSPFromBox().

#define GE_RAM_ALLOCATE_STRUCT type   )     (type *)geRam_Allocate (sizeof (type))
 

Definition at line 122 of file RAM.H.

Referenced by Attacker_TurretSpawn(), Bot_Create(), Client_AddMove(), Client_Create(), CreateGBSP(), ElectricFx_Create(), Fx_SystemCreate(), GameMgr_Create(), geActor_Create(), geActor_DefCreate(), geBody_CreateNull(), geBodyInst_Create(), geCamera_Create(), geCSNetMgr_Create(), geEntity_ClassCreate(), geEntity_FieldCreate(), geFog_Create(), geFont_AddCharacters(), geFont_Create(), geMotion_Create(), gePhysicsJoint_Create(), gePhysicsObject_Create(), gePhysicsSystem_AddJoint(), gePhysicsSystem_Create(), gePose_Create(), gePuppet_Create(), geSound_CreateSoundSystem(), geSprite_Create(), geStrBlock_Create(), geTKEvents_Create(), geTKEvents_CreateFromFile(), geWBitmap_Pool_Create(), geWorld_AddFog(), geWorld_AddPoly(), geWorld_Create(), geXFArray_Create(), Host_Create(), Light_WorldInit(), NetMgr_Create(), Server_Create(), Smoke_Create(), Sys_EngineCreate(), User_EngineInit(), User_WorldInit(), Water_Create(), and World_CreateBSPFromBox().

#define GE_RAM_REALLOC_ARRAY ptr,
type,
count   )     (type *)geRam_Realloc( (ptr), sizeof(type) * (count) );{type *XX=(ptr);}
 

Definition at line 126 of file RAM.H.

Referenced by geActor_AddMotion(), geBody_AddBone(), geBody_AddMaterial(), geBody_AddNormal(), geBody_AddSkinVertex(), geBody_AddToFaces(), gePose_AddJoint(), geWorld_AddActor(), and geWorld_AddSprite().

#define geRam_Allocate size   )     _geRam_DebugAllocate(size, __FILE__, __LINE__)
 

Definition at line 58 of file RAM.H.

Referenced by _Electric_BoltEffectCreate(), BitmapList_Create(), BumpMap_Create(), Console_Create(), CopySearchList(), CopyString(), CreateChannel(), CreateSoundManager(), DirTree_AddFile(), DirTree_Create(), DirTree_CreateFinder(), DirTree_SetFileHints(), DupChannel(), DuplicateString(), Fire_Create(), FSDos_FinderCreate(), FSDos_Open(), FSMemory_OpenNewSystem(), FSVFS_FinderCreate(), FSVFS_Open(), FSVFS_OpenNewSystem(), geBitmap_AllocSystemMip(), geBitmap_Palette_Create(), geBitmap_Palette_SetFormat(), geBitmap_WriteToFile(), geBitmapUtil_CreateHBITMAP(), geBody_ReadGeometry(), geEntity_Create(), geEntity_EntitySetCreate(), geEntity_EpairCreate(), geMotion_CreateFromBinaryFile(), geMotion_CreateFromFile(), geMotion_ReadBinaryLeaf(), geMotion_SetName(), gePath_Create(), gePath_CreateFromBinaryFile(), gePhysicsSystem_AddJoint(), geQKFrame_CreateFromBinaryFile(), geRam_AllocateClear(), geStrBlock_CreateFromBinaryFile(), geTClip_Push(), geTKArray_Create(), geTKArray_CreateEmpty(), geTKArray_CreateFromBinaryFile(), geTKEvents_CreateFromFile(), GetSoundData(), geVFile_CreateFinder(), geVFile_Open(), geVFile_OpenNewSystem(), geVKFrame_CreateFromBinaryFile(), Menu_AddItem(), Menu_Create(), Plasma_Create(), ProcEng_Create(), ReadChunk(), ReadTree(), SetFormat_Create(), SoftDrv_Init(), SpanBuffer_Create(), and Sys_EngineCreate().

#define geRam_Free xxx   )     geRam_Free_(xxx) ,(xxx)=NULL, StupidUnusedPointer=(xxx)
 

Definition at line 78 of file RAM.H.

Referenced by _Electric_BoltEffectCreate(), _Electric_BoltEffectDestroy(), _geRam_DebugRealloc(), Attacker_TurretDestroy(), BitmapList_Create(), BitmapList_Destroy(), Bot_Destroy(), BumpMap_Create(), BumpMap_Destroy(), ClearDupBuffers(), Client_Destroy(), Client_RemoveFirstMove(), Console_Destroy(), CreateSoundManager(), DestroySearchList(), DestroySoundManager(), DirTree_AddFile(), DirTree_Create(), DirTree_CreateFinder(), DirTree_Destroy(), DirTree_DestroyFinder(), DirTree_SetFileHints(), DupChannel(), ElectricFx_Destroy(), FillSoundChannel(), Fire_Create(), Fire_Destroy(), FreeAllChannels(), FreeChannel(), FSDos_Close(), FSDos_FinderCreate(), FSDos_FinderDestroy(), FSDos_Open(), FSMemory_Close(), FSVFS_Close(), FSVFS_FinderCreate(), FSVFS_FinderDestroy(), FSVFS_OpenNewSystem(), Fx_SystemDestroy(), GameMgr_FreeAllObjects(), GBSP_FreeGBSPFile(), geActor_Create(), geActor_DefDestroy(), geActor_Destroy(), geActor_DestroyDirect(), geBitmap_ClearMips(), geBitmap_Destroy(), geBitmap_Palette_Create(), geBitmap_Palette_CreateFromDriver(), geBitmap_Palette_CreateFromFile(), geBitmap_Palette_Destroy(), geBitmap_Palette_SetFormat(), geBitmap_SetFormat(), geBitmap_WriteToFile(), geBitmapUtil_CreateHBITMAP(), geBody_DestroyPossiblyIncompleteBody(), geBodyInst_Destroy(), geBodyInst_GetGeometryPrep(), geCamera_Destroy(), geCSNetMgr_Destroy(), geEntity_ClassDestroy(), geEntity_Destroy(), geEntity_EntitySetDestroy(), geEntity_EpairDestroy(), geEntity_FieldDestroy(), geFog_Destroy(), geFont_AddCharacters(), geFont_Destroy(), geFont_DrawUsingDIB(), geMotion_Destroy(), geMotion_RemoveSubMotion(), geMotion_SetName(), gePath_CreateFromBinaryFile(), gePath_Destroy(), gePhysicsJoint_Destroy(), gePhysicsObject_Destroy(), gePhysicsSystem_AddJoint(), gePhysicsSystem_Destroy(), gePose_Create(), gePose_Destroy(), gePuppet_Create(), gePuppet_Destroy(), gePuppet_FetchTextures(), geQKFrame_CreateFromBinaryFile(), geSound_CreateSoundSystem(), geSound_DestroySoundSystem(), geSprite_Destroy(), geStrBlock_Destroy(), geTClip_Pop(), geTKArray_CreateFromBinaryFile(), geTKArray_Destroy(), geTKEvents_Create(), geTKEvents_CreateFromFile(), geTKEvents_Delete(), geTKEvents_Destroy(), GetSoundData(), geVFile_Close(), geVFile_CloseAPI(), geVFile_CreateFinder(), geVFile_DestroyFinder(), geVFile_Open(), geVFile_OpenNewSystem(), geVKFrame_CreateFromBinaryFile(), geWBitmap_Pool_CreateAllWBitmaps(), geWBitmap_Pool_Destroy(), geWBitmap_Pool_DestroyAllWBitmaps(), geWorld_AddFog(), geWorld_Create(), geWorld_Free(), geWorld_RemoveFog(), geWorld_RemovePoly(), geXFArray_Create(), geXFArray_Destroy(), Host_Create(), Host_Destroy(), Light_WorldShutdown(), Menu_AddItem(), Menu_Destroy(), ModeList_Destroy(), NetMgr_FreeAllObjects(), Particles_Destroy(), Plasma_Create(), Plasma_Destroy(), ProcEng_Destroy(), ReadTree(), Server_Create(), Server_Destroy(), SetFormat_Destroy(), Smoke_Destroy(), Smoke_InitBitmap(), SoftDrv_Shutdown(), SpanBuffer_Create(), SpanBuffer_Destroy(), Surf_WorldInit(), Surf_WorldShutdown(), Sys_EngineCreate(), Sys_EngineFree(), User_EngineShutdown(), User_WorldShutdown(), Vis_WorldInit(), Vis_WorldShutdown(), and Water_Destroy().

#define geRam_Realloc ptr,
newsize   )     _geRam_DebugRealloc(ptr, newsize, __FILE__, __LINE__)
 

Definition at line 87 of file RAM.H.

Referenced by geMotion_AddPath(), geMotion_AddSubMotion(), geMotion_RemoveSubMotion(), gePhysicsSystem_AddJoint(), gePhysicsSystem_AddObject(), gePuppet_Render(), gePuppet_RenderThroughFrustum(), geStrBlock_Append(), geStrBlock_Delete(), geTKArray_DeleteElement(), geTKArray_Insert(), geTKEvents_Delete(), geTKEvents_Insert(), geVFile_RegisterFileSystemInternal(), ModeList_Create(), and TestForExpansion().


Typedef Documentation

typedef int(* geRam_CriticalCallbackFunction)(void)
 

Definition at line 31 of file RAM.H.

Referenced by geRam_SetCriticalCallback().


Function Documentation

GENESISAPI void* _geRam_DebugAllocate uint32  size,
const char *  pFile,
int  line
 

Definition at line 247 of file Ram.c.

References EXTRA_SIZE, GENESISAPI, geRam_CurrentlyUsed, geRam_DoCriticalCallback(), geRam_MaximumNumberOfAllocations, geRam_MaximumUsed, geRam_NumberOfAllocations, geRam_SetupBlock(), HEADER_SIZE, INITIALIZE_MEMORY, and NULL.

Referenced by _geRam_DebugRealloc().

00248         {
00249       char *p;
00250 
00251       do
00252       {
00253           p = (char*)_malloc_dbg (size + EXTRA_SIZE, _NORMAL_BLOCK, pFile, line);
00254       } while ((p == NULL) && geRam_DoCriticalCallback ());
00255 
00256       if (p == NULL)
00257       {
00258          return NULL;
00259       }
00260 
00261       // setup size stamps and memory overwrite checks
00262       geRam_SetupBlock (p, size, INITIALIZE_MEMORY);
00263 
00264       // and update the allocations stuff
00265       geRam_NumberOfAllocations++;
00266       geRam_CurrentlyUsed += size;
00267 
00268       if (geRam_NumberOfAllocations > geRam_MaximumNumberOfAllocations)
00269       {
00270           geRam_MaximumNumberOfAllocations = geRam_NumberOfAllocations;
00271       }
00272       if (geRam_CurrentlyUsed > geRam_MaximumUsed)
00273       {
00274           geRam_MaximumUsed = geRam_CurrentlyUsed;
00275       }
00276 
00277       return p+HEADER_SIZE;
00278         }

GENESISAPI void* _geRam_DebugRealloc void *  ptr,
uint32  size,
const char *  pFile,
int  line
 

Definition at line 384 of file Ram.c.

References _geRam_DebugAllocate(), DONT_INITIALIZE, EXTRA_SIZE, GENESISAPI, geRam_CurrentlyUsed, geRam_DoCriticalCallback(), geRam_Free, geRam_MaximumUsed, geRam_SetupBlock(), HEADER_SIZE, NULL, ram_verify_block(), and uint32.

00385     {
00386         char *p;
00387         char * NewPtr;
00388         uint32 size;
00389 
00390         // if realloc is called with NULL, just treat it like an alloc
00391         if (ptr == NULL)
00392         {
00393             return _geRam_DebugAllocate(newsize, pFile, line);
00394         }
00395 
00396         // verify the block
00397         p = ram_verify_block (ptr);
00398         if (p == NULL)
00399         {
00400             return NULL;
00401         }
00402 
00403         // if newsize is NULL, then it's a free and return NULL
00404         if (newsize == 0)
00405         {
00406             geRam_Free (ptr);
00407             return NULL;
00408         }
00409 
00410         // gotta get the size before I realloc it...
00411         size = *((uint32 *)p);
00412 
00413         do
00414         {
00415             NewPtr = (char *)_realloc_dbg(p, newsize+EXTRA_SIZE, _NORMAL_BLOCK, pFile, line);
00416         } while ((NewPtr == NULL) && geRam_DoCriticalCallback ());
00417 
00418         // if allocation failed, return NULL...
00419         if (NewPtr == NULL)
00420         {
00421             return NULL;
00422         }
00423 
00424         geRam_SetupBlock (NewPtr, newsize, DONT_INITIALIZE);
00425 
00426         geRam_CurrentlyUsed += (newsize - size);
00427         if (geRam_CurrentlyUsed > geRam_MaximumUsed)
00428         {
00429             geRam_MaximumUsed = geRam_CurrentlyUsed;
00430         }
00431         assert ((geRam_CurrentlyUsed >= 0) && "free()d more ram than you allocated!");
00432 
00433         return NewPtr + HEADER_SIZE;
00434     }

GENESISAPI void geRam_AddAllocation int  n,
uint32  size
 

Definition at line 503 of file Ram.c.

References GENESISAPI, geRam_CurrentlyUsed, geRam_MaximumNumberOfAllocations, geRam_MaximumUsed, and geRam_NumberOfAllocations.

00504     {
00505         // and update the allocations stuff
00506         geRam_NumberOfAllocations += n;
00507         geRam_CurrentlyUsed += size;
00508 
00509         if (geRam_NumberOfAllocations > geRam_MaximumNumberOfAllocations)
00510         {
00511             geRam_MaximumNumberOfAllocations = geRam_NumberOfAllocations;
00512         }
00513         if (geRam_CurrentlyUsed > geRam_MaximumUsed)
00514         {
00515             geRam_MaximumUsed = geRam_CurrentlyUsed;
00516         }
00517     }

GENESISAPI void* geRam_AllocateClear uint32  size  ) 
 

Definition at line 107 of file Ram.c.

References GENESISAPI, geRam_Allocate, and uint32.

Referenced by createPaletteFast(), createPaletteGoodSub(), and Particles_Create().

00108 {
00109 void * mem;
00110         size = (size + 3)&(~(uint32)3);
00111         mem = geRam_Allocate(size);
00112         if ( mem )
00113         {
00114                 memset(mem,0,size);
00115         }
00116 return mem;
00117 }

GENESISAPI int geRam_EnableCriticalCallback int  add  ) 
 

Definition at line 64 of file Ram.c.

References GENESISAPI, and geRam_CriticalAllocationCount.

00065 {
00066         geRam_CriticalAllocationCount += add;
00067         return geRam_CriticalAllocationCount;
00068 }

GENESISAPI void geRam_Free_ void *  ptr  ) 
 

Definition at line 353 of file Ram.c.

References EXTRA_SIZE, FreeFillerByte, GENESISAPI, geRam_CurrentlyUsed, geRam_NumberOfAllocations, NULL, ram_verify_block(), and uint32.

00354     {
00355         char *p;
00356         uint32 size;
00357 
00358         // make sure it's a valid block...
00359         p = ram_verify_block (ptr);
00360         if (p == NULL)
00361         {
00362             return;
00363         }
00364 
00365         // gotta get the size before you free it
00366         size = *((uint32 *)p);
00367 
00368         // fill it with trash...
00369         memset (p, FreeFillerByte, size+EXTRA_SIZE);
00370 
00371         // free the memory
00372         free (p);
00373 
00374         // update allocations
00375         geRam_NumberOfAllocations--;
00376         assert ((geRam_NumberOfAllocations >= 0) && "free()d more ram than you allocated!");
00377 
00378         geRam_CurrentlyUsed -= size;
00379         assert ((geRam_CurrentlyUsed >= 0) && "free()d more ram than you allocated!");
00380     }

geBoolean geRam_IsValidPtr void *  ptr  ) 
 

Definition at line 523 of file Ram.c.

References GE_FALSE, GE_TRUE, geBoolean, HEADER_SIZE, MemStamp, MemStampSize, NULL, SizeSize, and uint32.

Referenced by MemBlock_IsValid().

00524 {
00525 char * p = ptr;
00526 uint32 size;
00527 
00528         if (p == NULL) return GE_FALSE;
00529 
00530         // make p point to the beginning of the block
00531         p -= HEADER_SIZE;
00532 
00533         // get size from block
00534         size = *((uint32 *)p);
00535 
00536         // check stamp at front
00537         if (memcmp (p+SizeSize, MemStamp, MemStampSize) != 0)
00538         {
00539                 return GE_FALSE;
00540         }
00541 
00542         // and at back
00543         if (memcmp (p+HEADER_SIZE+size, MemStamp, MemStampSize) != 0)
00544         {
00545                 return GE_FALSE;
00546         }
00547 
00548 return GE_TRUE;
00549 }

GENESISAPI void geRam_ReportAllocations void   ) 
 

Definition at line 494 of file Ram.c.

References GENESISAPI.

00495 {
00496         _CrtDumpMemoryLeaks();
00497 }

GENESISAPI geRam_CriticalCallbackFunction geRam_SetCriticalCallback geRam_CriticalCallbackFunction  callback  ) 
 

Definition at line 76 of file Ram.c.

References geRam_CriticalCallback, and geRam_CriticalCallbackFunction.

00079 {
00080     geRam_CriticalCallbackFunction OldCallback;
00081 
00082     OldCallback = geRam_CriticalCallback;
00083         geRam_CriticalCallback = critical_callback;
00084     return OldCallback;
00085 }


Variable Documentation

int32 geRam_CurrentlyUsed
 

Definition at line 109 of file RAM.H.

Referenced by _geRam_DebugAllocate(), _geRam_DebugRealloc(), geRam_AddAllocation(), and geRam_Free_().

int32 geRam_MaximumNumberOfAllocations
 

Definition at line 112 of file RAM.H.

Referenced by _geRam_DebugAllocate(), and geRam_AddAllocation().

int32 geRam_MaximumUsed
 

Definition at line 111 of file RAM.H.

Referenced by _geRam_DebugAllocate(), _geRam_DebugRealloc(), and geRam_AddAllocation().

int32 geRam_NumberOfAllocations
 

Definition at line 110 of file RAM.H.

Referenced by _geRam_DebugAllocate(), geRam_AddAllocation(), and geRam_Free_().

void* StupidUnusedPointer
 

Definition at line 74 of file RAM.H.


Generated on Tue Sep 30 12:37:59 2003 for GTestAndEngine by doxygen 1.3.2