2016-09-24 04:43:59 +00:00
|
|
|
#include "Dengine/MemoryArena.h"
|
|
|
|
|
|
|
|
void memory_arenaInit(MemoryArena_ *arena, void *base, size_t size)
|
|
|
|
{
|
2016-11-27 06:26:23 +00:00
|
|
|
arena->size = size;
|
|
|
|
arena->used = 0;
|
|
|
|
arena->base = CAST(u8 *) base;
|
|
|
|
arena->tempMemoryCount = 0;
|
|
|
|
}
|
|
|
|
|
2016-11-27 10:16:12 +00:00
|
|
|
TempMemory memory_beginTempRegion(MemoryArena_ *arena)
|
2016-11-27 06:26:23 +00:00
|
|
|
{
|
|
|
|
TempMemory result = {0};
|
|
|
|
result.arena = arena;
|
|
|
|
result.used = arena->used;
|
|
|
|
|
|
|
|
arena->tempMemoryCount++;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-27 10:16:12 +00:00
|
|
|
void memory_endTempRegion(TempMemory tempMemory)
|
2016-11-27 06:26:23 +00:00
|
|
|
{
|
|
|
|
MemoryArena_ *arena = tempMemory.arena;
|
|
|
|
ASSERT(arena->used > tempMemory.used)
|
|
|
|
|
|
|
|
arena->used = tempMemory.used;
|
|
|
|
ASSERT(arena->tempMemoryCount > 0)
|
|
|
|
|
|
|
|
arena->tempMemoryCount--;
|
2016-09-24 04:43:59 +00:00
|
|
|
}
|