Add ZG_Free function for zonegroup memory.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6208 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
e55f21585e
commit
dd9bdab8dc
2 changed files with 37 additions and 2 deletions
|
@ -540,7 +540,16 @@ typedef struct zonegroupblock_s
|
|||
{
|
||||
union
|
||||
{
|
||||
struct zonegroupblock_s *next;
|
||||
struct
|
||||
{
|
||||
struct zonegroupblock_s *next;
|
||||
struct zonegroupblock_s *prev;
|
||||
#ifdef _DEBUG
|
||||
#define ZONEGROUP_SENTINAL 0x709ef00d
|
||||
unsigned int sentinal;
|
||||
unsigned int size;
|
||||
#endif
|
||||
};
|
||||
vec4_t align16;
|
||||
};
|
||||
} zonegroupblock_t;
|
||||
|
@ -561,11 +570,36 @@ void *QDECL ZG_Malloc(zonegroup_t *ctx, size_t size)
|
|||
newm = Z_Malloc(size);
|
||||
#endif
|
||||
|
||||
newm->prev = NULL;
|
||||
if (ctx->first)
|
||||
((zonegroupblock_t*)ctx->first)->prev = newm;
|
||||
newm->next = ctx->first;
|
||||
ctx->first = newm;
|
||||
ctx->totalbytes += size;
|
||||
|
||||
#ifdef _DEBUG
|
||||
newm->sentinal = ZONEGROUP_SENTINAL;
|
||||
newm->size = size;
|
||||
#endif
|
||||
return(void*)(newm+1);
|
||||
}
|
||||
void ZG_Free(zonegroup_t *ctx, void *ptr)
|
||||
{
|
||||
zonegroupblock_t *mem = (zonegroupblock_t*)ptr-1;
|
||||
if (mem->prev)
|
||||
mem->prev->next = mem->next;
|
||||
else
|
||||
ctx->first = mem->next;
|
||||
if (mem->next)
|
||||
mem->next->prev = mem->prev;
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (mem->sentinal != ZONEGROUP_SENTINAL)
|
||||
Sys_Error("Corrupt memory");
|
||||
ctx->totalbytes -= mem->size;
|
||||
#endif
|
||||
BZ_Free(mem);
|
||||
}
|
||||
void ZG_FreeGroup(zonegroup_t *ctx)
|
||||
{
|
||||
zonegroupblock_t *old;
|
||||
|
|
|
@ -133,7 +133,8 @@ typedef struct zonegroup_s
|
|||
} zonegroup_t;
|
||||
void *QDECL ZG_Malloc(zonegroup_t *ctx, size_t size);
|
||||
void *ZG_MallocNamed(zonegroup_t *ctx, size_t size, char *file, int line);
|
||||
void ZG_FreeGroup(zonegroup_t *ctx);
|
||||
void QDECL ZG_Free(zonegroup_t *ctx, void *ptr);
|
||||
void QDECL ZG_FreeGroup(zonegroup_t *ctx);
|
||||
|
||||
#ifdef USE_MSVCRT_DEBUG
|
||||
#define BZ_Malloc(size) BZ_MallocNamed(size, __FILE__, __LINE__)
|
||||
|
|
Loading…
Reference in a new issue