mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 05:08:14 +00:00
Merge tag 'dev-2025-08'
# Conflicts: # .gitignore
This commit is contained in:
@@ -2223,6 +2223,9 @@ Initialize a buddy allocator.
|
||||
|
||||
This procedure initializes the buddy allocator `b` with a backing buffer `data`
|
||||
and block alignment specified by `alignment`.
|
||||
|
||||
`alignment` may be any power of two, but the backing buffer must be aligned to
|
||||
at least `size_of(Buddy_Block)`.
|
||||
*/
|
||||
buddy_allocator_init :: proc(b: ^Buddy_Allocator, data: []byte, alignment: uint, loc := #caller_location) {
|
||||
assert(data != nil)
|
||||
@@ -2233,7 +2236,7 @@ buddy_allocator_init :: proc(b: ^Buddy_Allocator, data: []byte, alignment: uint,
|
||||
alignment = size_of(Buddy_Block)
|
||||
}
|
||||
ptr := raw_data(data)
|
||||
assert(uintptr(ptr) % uintptr(alignment) == 0, "data is not aligned to minimum alignment", loc)
|
||||
assert(uintptr(ptr) % uintptr(alignment) == 0, "The data is not aligned to the minimum alignment, which must be at least `size_of(Buddy_Block)`.", loc)
|
||||
b.head = (^Buddy_Block)(ptr)
|
||||
b.head.size = len(data)
|
||||
b.head.is_free = true
|
||||
|
||||
@@ -20,6 +20,17 @@ new_aligned :: proc(arena: ^Arena, $T: typeid, alignment: uint, loc := #caller_l
|
||||
return
|
||||
}
|
||||
|
||||
// The `new_clone` procedure allocates memory for a type `T` from a `virtual.Arena`. The second argument is a value that
|
||||
// is to be copied to the allocated data. The value returned is a pointer to a newly allocated value of that type using the specified allocator.
|
||||
@(require_results)
|
||||
new_clone :: proc(arena: ^Arena, data: $T, loc := #caller_location) -> (ptr: ^T, err: Allocator_Error) {
|
||||
ptr, err = new_aligned(arena, T, align_of(T), loc)
|
||||
if ptr != nil && err == nil {
|
||||
ptr^ = data
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// `make_slice` allocates and initializes a slice. Like `new`, the second argument is a type, not a value.
|
||||
// Unlike `new`, `make`'s return value is the same as the type of its argument, not a pointer to it.
|
||||
//
|
||||
|
||||
@@ -89,8 +89,8 @@ memory_block_alloc :: proc(committed, reserved: uint, alignment: uint = 0, flags
|
||||
reserved = align_formula(reserved, page_size)
|
||||
committed = clamp(committed, 0, reserved)
|
||||
|
||||
total_size := uint(reserved + max(alignment, size_of(Platform_Memory_Block)))
|
||||
base_offset := uintptr(max(alignment, size_of(Platform_Memory_Block)))
|
||||
total_size := reserved + alignment + size_of(Platform_Memory_Block)
|
||||
base_offset := mem.align_forward_uintptr(size_of(Platform_Memory_Block), max(uintptr(alignment), align_of(Platform_Memory_Block)))
|
||||
protect_offset := uintptr(0)
|
||||
|
||||
do_protection := false
|
||||
|
||||
Reference in New Issue
Block a user