Skip to content

Commit

Permalink
Fix issue odin-lang#4834
Browse files Browse the repository at this point in the history
The logic that determines whether we need to allocate more space does
not account having to align the end forward for requested alignment.
  • Loading branch information
jasonKercher committed Feb 12, 2025
1 parent 4c4b481 commit 19302e0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/mem/virtual/arena.odin
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ arena_alloc :: proc(arena: ^Arena, size: uint, alignment: uint, loc := #caller_l
switch arena.kind {
case .Growing:
needed := mem.align_forward_uint(size, alignment)
if arena.curr_block != nil {
ptr := uintptr(arena.curr_block.base[arena.curr_block.used:])
mask := uintptr(alignment)-1
if ptr & mask != 0 {
needed += uint(uintptr(alignment) - (ptr & mask))
}
}

if arena.curr_block == nil || (safe_add(arena.curr_block.used, needed) or_else 0) > arena.curr_block.reserved {
if arena.minimum_block_size == 0 {
arena.minimum_block_size = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE
Expand Down

0 comments on commit 19302e0

Please sign in to comment.