undo scratch alloc change

This commit is contained in:
Matthew 2025-09-21 17:16:35 +10:00
parent 8d651ab1fc
commit 85177acdd0

31
alloc.d
View File

@ -10,14 +10,14 @@ import core.stdc.string : memset;
import core.memory;
static Scratch g_scratch;
static u64 g_scratch_index;
const DEFAULT_ALIGNMENT = (void *).sizeof * 2;
struct Scratch
{
Arena[] arenas;
u64 index;
bool init;
Arena arena;
bool init;
}
struct ArenaPool
@ -189,34 +189,25 @@ Free(T)(T* ptr)
}
void
ResetScratch(u64 size, u64 count)
ResetScratch(u64 size)
{
with(g_scratch)
if(!g_scratch.init)
{
if(!init)
{
arenas = AllocArray!(Arena)(count);
for(u64 i = 0; i < count; i += 1)
{
arenas[i] = CreateArena(size);
}
g_scratch.init = true;
}
index = index % count;
Reset(&arenas[index]);
g_scratch.arena = CreateArena(size);
g_scratch.init = true;
}
Reset(&g_scratch.arena);
}
T*
ScratchAlloc(T)()
{
return Alloc!(T)(&g_scratch.arenas[g_scratch.index]);
return Alloc!(T)(&g_scratch.arena);
}
T[]
ScratchAlloc(T)(u64 count)
{
return AllocArray!(T)(&g_scratch.arenas[g_scratch.index], count);
return AllocArray!(T)(&g_scratch.arena, count);
}