undo scratch alloc change

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

25
alloc.d
View File

@ -10,13 +10,13 @@ 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;
} }
@ -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);
{
arenas = AllocArray!(Arena)(count);
for(u64 i = 0; i < count; i += 1)
{
arenas[i] = CreateArena(size);
}
g_scratch.init = true; g_scratch.init = true;
} }
index = index % count; Reset(&g_scratch.arena);
Reset(&arenas[index]);
}
} }
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);
} }