Block allocator scratch

This commit is contained in:
KK
2026-07-03 21:14:23 +02:00
parent cda805574f
commit b2c3cac73d
2 changed files with 63 additions and 9 deletions

View File

@@ -331,7 +331,34 @@ API void *BlockArenaAllocatorProc(void *object, int kind, void *p, size_t size)
}
#if OS_WASM
BlockArena ScratchArenas[4];
API void InitScratch() {
for (int i = 0; i < 4; i += 1) {
if (!ScratchArenas[i].blocks) Init(&ScratchArenas[i]);
}
}
API BlockArena *GetScratchEx(BlockArena **conflicts, int conflict_count) {
BlockArena *unoccupied = 0;
for (int i = 0; i < Lengthof(ScratchArenas); i += 1) {
BlockArena *from_pool = &ScratchArenas[i];
unoccupied = from_pool;
for (int conflict_i = 0; conflict_i < conflict_count; conflict_i += 1) {
BlockArena *from_conflict = conflicts[conflict_i];
if (from_pool == from_conflict) {
unoccupied = 0;
break;
}
}
if (unoccupied) {
break;
}
}
// Failed to get free scratch memory, this is a fatal error, this shouldnt happen
Assert(unoccupied);
return unoccupied;
}
#else
thread_local VirtualArena ScratchArenas[4];