diff --git a/alloc.d b/alloc.d index e55530a..16f7e81 100644 --- a/alloc.d +++ b/alloc.d @@ -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); }