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; import core.memory;
static Scratch g_scratch; static Scratch g_scratch;
static u64 g_scratch_index;
const DEFAULT_ALIGNMENT = (void *).sizeof * 2; const DEFAULT_ALIGNMENT = (void *).sizeof * 2;
struct Scratch struct Scratch
{ {
Arena[] arenas; Arena arena;
u64 index; bool init;
bool init;
} }
struct ArenaPool struct ArenaPool
@ -189,34 +189,25 @@ Free(T)(T* ptr)
} }
void void
ResetScratch(u64 size, u64 count) ResetScratch(u64 size)
{ {
with(g_scratch) if(!g_scratch.init)
{ {
if(!init) g_scratch.arena = CreateArena(size);
{ g_scratch.init = true;
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]);
} }
Reset(&g_scratch.arena);
} }
T* T*
ScratchAlloc(T)() ScratchAlloc(T)()
{ {
return Alloc!(T)(&g_scratch.arenas[g_scratch.index]); return Alloc!(T)(&g_scratch.arena);
} }
T[] T[]
ScratchAlloc(T)(u64 count) ScratchAlloc(T)(u64 count)
{ {
return AllocArray!(T)(&g_scratch.arenas[g_scratch.index], count); return AllocArray!(T)(&g_scratch.arena, count);
} }