Add stack allocation to temp allocator;

It can be used to push the current cursor onto the stack, perform some
tmep allocations, and then pop the stack to "free" them all at once.
This can be nice if you're doing some temporary allocations that aren't
going to be needed when the function returns, since it reduces the
amount of allocator growth a bit.

This allocator is meant to be threadlocal eventually, so there are no
thread-safety concerns.
This commit is contained in:
bjorn 2022-06-26 20:52:59 -07:00
parent cbe24f482f
commit bac57dc0d2
1 changed files with 10 additions and 0 deletions

View File

@ -319,6 +319,8 @@ static struct {
static void* tempAlloc(size_t size);
static void* tempGrow(void* p, size_t size);
static uint32_t tempPush(void);
static void tempPop(uint32_t stack);
static void beginFrame(void);
static void cleanupPasses(void);
static uint32_t getLayout(gpu_slot* slots, uint32_t count);
@ -3764,6 +3766,14 @@ static void* tempGrow(void* p, size_t size) {
return memcpy(new, p, size >> 1);
}
static uint32_t tempPush(void) {
return state.allocator.cursor;
}
static void tempPop(uint32_t stack) {
state.allocator.cursor = stack;
}
static void beginFrame(void) {
if (state.active) {
return;