mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
add zeroing to new region from realloc
This commit is contained in:
+11
-2
@@ -206,11 +206,20 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aligned_resize :: proc(p: rawptr, old_size: int, new_size: int, new_alignment: int) -> ([]byte, mem.Allocator_Error) {
|
aligned_resize :: proc(p: rawptr, old_size: int, new_size: int, new_alignment: int) -> (new_memory: []byte, err: mem.Allocator_Error) {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return aligned_alloc(new_size, new_alignment, p)
|
|
||||||
|
new_memory = aligned_alloc(new_size, new_alignment, p) or_return
|
||||||
|
when ODIN_OS != "windows" {
|
||||||
|
// NOTE: realloc does not zero the new memory, so we do it
|
||||||
|
if new_size > old_size {
|
||||||
|
new_region := mem.raw_data(new_memory[old_size:])
|
||||||
|
mem.zero(new_region, new_size - old_size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
|
|||||||
Reference in New Issue
Block a user