Implement memory decommit
This commit is contained in:
+12
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user