Browse Source

add resize_non_zeroed to query features

Colin Davidson 1 year ago
parent
commit
991c1d4446
2 changed files with 28 additions and 5 deletions
  1. 22 2
      core/mem/alloc.odin
  2. 6 3
      core/mem/allocators.odin

+ 22 - 2
core/mem/alloc.odin

@@ -245,12 +245,26 @@ default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment:
 	res = raw_data(data)
 	return
 }
+
+@(require_results)
+default_resize_bytes_align_non_zeroed :: proc(old_data: []byte, new_size, alignment: int, allocator := context.allocator, loc := #caller_location) -> ([]byte, Allocator_Error) {
+    return _default_resize_bytes_align(old_data, new_size, alignment, false, allocator, loc)
+}
 @(require_results)
 default_resize_bytes_align :: proc(old_data: []byte, new_size, alignment: int, allocator := context.allocator, loc := #caller_location) -> ([]byte, Allocator_Error) {
+    return _default_resize_bytes_align(old_data, new_size, alignment, true, allocator, loc)
+}
+
+@(require_results)
+_default_resize_bytes_align :: #force_inline proc(old_data: []byte, new_size, alignment: int, should_zero: bool, allocator := context.allocator, loc := #caller_location) -> ([]byte, Allocator_Error) {
 	old_memory := raw_data(old_data)
 	old_size := len(old_data)
 	if old_memory == nil {
-		return alloc_bytes(new_size, alignment, allocator, loc)
+        if should_zero {
+            return alloc_bytes(new_size, alignment, allocator, loc)
+        } else {
+            return alloc_bytes_non_zeroed(new_size, alignment, allocator, loc)
+        }
 	}
 
 	if new_size == 0 {
@@ -262,7 +276,13 @@ default_resize_bytes_align :: proc(old_data: []byte, new_size, alignment: int, a
 		return old_data, .None
 	}
 
-	new_memory, err := alloc_bytes(new_size, alignment, allocator, loc)
+    new_memory : []byte
+    err : Allocator_Error
+    if should_zero {
+        new_memory, err = alloc_bytes(new_size, alignment, allocator, loc)
+    } else {
+        new_memory, err = alloc_bytes_non_zeroed(new_size, alignment, allocator, loc)
+    }
 	if new_memory == nil || err != nil {
 		return nil, err
 	}

+ 6 - 3
core/mem/allocators.odin

@@ -85,13 +85,16 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
 	case .Free_All:
 		arena.offset = 0
 
-	case .Resize, .Resize_Non_Zeroed:
-		return default_resize_bytes_align(byte_slice(old_memory, old_size), size, alignment, arena_allocator(arena))
+    case .Resize:
+        return default_resize_bytes_align(byte_slice(old_memory, old_size), size, alignment, arena_allocator(arena))
+
+    case .Resize_Non_Zeroed:
+        return default_resize_bytes_align_non_zeroed(byte_slice(old_memory, old_size), size, alignment, arena_allocator(arena))
 
 	case .Query_Features:
 		set := (^Allocator_Mode_Set)(old_memory)
 		if set != nil {
-			set^ = {.Alloc, .Alloc_Non_Zeroed, .Free_All, .Resize, .Query_Features}
+			set^ = {.Alloc, .Alloc_Non_Zeroed, .Free_All, .Resize, .Resize_Non_Zeroed, .Query_Features}
 		}
 		return nil, nil