39 lines
873 B
C
39 lines
873 B
C
void*
|
|
persistent_mem_alloc(memory_region_t* region, size_t count, size_t size)
|
|
{
|
|
size_t total_size = count * size;
|
|
|
|
LOG_ASSERT(region->current + total_size < region->end,
|
|
"Exceeded bounds of engine memory by %d bytes",
|
|
region->current + total_size - region->end);
|
|
|
|
void* result = region->current;
|
|
region->current += total_size;
|
|
|
|
return result;
|
|
}
|
|
|
|
void
|
|
persistent_mem_reset(memory_region_t* region)
|
|
{
|
|
region->current = region->begin;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|