From 920487be049fd115fbc454bc4dde88ec08f77c2c Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Sun, 13 Apr 2025 22:22:12 -0400 Subject: [PATCH] Zero only needed part of memory when changing size categories --- base/runtime/heap_allocator_implementation.odin | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/base/runtime/heap_allocator_implementation.odin b/base/runtime/heap_allocator_implementation.odin index be01aab37..a3bb35ad1 100644 --- a/base/runtime/heap_allocator_implementation.odin +++ b/base/runtime/heap_allocator_implementation.odin @@ -1846,8 +1846,11 @@ heap_resize :: proc "contextless" (old_ptr: rawptr, old_size: int, new_size: int if new_category != old_category { // A change in size category cannot be optimized. - new_ptr = heap_alloc(new_size, zero_memory) + new_ptr = heap_alloc(new_size, false) intrinsics.mem_copy_non_overlapping(new_ptr, old_ptr, min(old_size, new_size)) + if zero_memory && new_size > old_size { + intrinsics.mem_zero_volatile(rawptr(uintptr(new_ptr) + uintptr(old_size)), new_size - old_size) + } heap_free(old_ptr) heap_debug_cover(.Resize_Crossed_Size_Categories) return