1
0
Fork 0
2022-untitled-game/code/src/engine/memory.c

48 lines
1.1 KiB
C

void*
engine_mem_alloc(size_t count, size_t size)
{
size_t total_size = count * size;
LOG_ASSERT(g_memory->engine.current + total_size < g_memory->engine.end,
"Exceeded bounds of engine memory by %d bytes",
g_memory->engine.current + total_size - g_memory->engine.end);
void* result = g_memory->engine.current;
g_memory->engine.current += total_size;
return result;
}
void*
game_mem_alloc(size_t count, size_t size)
{
size_t total_size = count * size;
LOG_ASSERT(g_memory->game.current + total_size < g_memory->game.end,
"Exceeded bounds of game memory by %d bytes",
g_memory->game.current + total_size - g_memory->game.end);
void* result = g_memory->game.current;
g_memory->game.current += total_size;
return result;
}
void*
scratch_mem_alloc(size_t count, size_t size)
{
size_t total_size = count * size;
// Reset to beginning, overwriting old stale data
if (g_memory->scratch.current + total_size > g_memory->scratch.end) {
LOG_DEBUG("Transient memory reset to beginning");
g_memory->scratch.current = g_memory->scratch.begin;
}
void* result = g_memory->scratch.current;
g_memory->scratch.current += total_size;
return result;
}