Implement memory decommit

This commit is contained in:
Nils O. Selåsdal
2026-06-16 23:46:52 +02:00
parent 612b9f0e8a
commit 4a75eddd8f
3 changed files with 48 additions and 4 deletions
+12 -1
View File
@@ -115,7 +115,7 @@ void arena_reset_to(Arena *arena, U64 total_offset)
MemoryBlock *prev = block->prev;
if (block->arena_offset >= total_offset) {
ASAN_UNPOISON_MEMORY_REGION(block->base, block->size);
ASAN_UNPOISON_MEMORY_REGION(block->base, block->committed_end);
memory_free(block->base, block->size);
arena->current = prev;
} else {
@@ -123,8 +123,19 @@ void arena_reset_to(Arena *arena, U64 total_offset)
new_pos = Max(MemoryBlock_Header_Size, new_pos);
// Disallow arbitrary pops to positions that previously were not commited.
Assert(new_pos <= block->committed_end);
Assert(new_pos <= block->size);
block->first_free = new_pos;
ASAN_POISON_MEMORY_REGION(&block->base[block->first_free], memoryblock_available(block));
if ((arena->flags & ArenaFlag_NoDecommit) == 0) {
U32 aligned_pos = RoundUpToMultiple(block->first_free, arena->commit_size);
if (aligned_pos < block->committed_end) {
ASAN_UNPOISON_MEMORY_REGION(&block->base[aligned_pos], block->committed_end);
memory_decommit(&block->base[aligned_pos], block->committed_end - aligned_pos);
block->committed_end = aligned_pos;
}
}
break;
}