fix asm instruction, make scratch allocator able to work per frame
This commit is contained in:
parent
ff94c5cb5e
commit
8d651ab1fc
30
alloc.d
30
alloc.d
@ -15,8 +15,9 @@ const DEFAULT_ALIGNMENT = (void *).sizeof * 2;
|
||||
|
||||
struct Scratch
|
||||
{
|
||||
Arena arena;
|
||||
bool init;
|
||||
Arena[] arenas;
|
||||
u64 index;
|
||||
bool init;
|
||||
}
|
||||
|
||||
struct ArenaPool
|
||||
@ -188,25 +189,34 @@ Free(T)(T* ptr)
|
||||
}
|
||||
|
||||
void
|
||||
ResetScratch(u64 size)
|
||||
ResetScratch(u64 size, u64 count)
|
||||
{
|
||||
if(!g_scratch.init)
|
||||
with(g_scratch)
|
||||
{
|
||||
g_scratch.arena = CreateArena(size);
|
||||
g_scratch.init = true;
|
||||
}
|
||||
if(!init)
|
||||
{
|
||||
arenas = AllocArray!(Arena)(count);
|
||||
for(u64 i = 0; i < count; i += 1)
|
||||
{
|
||||
arenas[i] = CreateArena(size);
|
||||
}
|
||||
|
||||
Reset(&g_scratch.arena);
|
||||
g_scratch.init = true;
|
||||
}
|
||||
|
||||
index = index % count;
|
||||
Reset(&arenas[index]);
|
||||
}
|
||||
}
|
||||
|
||||
T*
|
||||
ScratchAlloc(T)()
|
||||
{
|
||||
return Alloc!(T)(&g_scratch.arena);
|
||||
return Alloc!(T)(&g_scratch.arenas[g_scratch.index]);
|
||||
}
|
||||
|
||||
T[]
|
||||
ScratchAlloc(T)(u64 count)
|
||||
{
|
||||
return AllocArray!(T)(&g_scratch.arena, count);
|
||||
return AllocArray!(T)(&g_scratch.arenas[g_scratch.index], count);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user