mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Make Growing_Arena reserve memory first and then commit as needed
It just committed all at once to begin with
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
package mem_virtual
|
package mem_virtual
|
||||||
|
|
||||||
|
arena_init :: proc{
|
||||||
|
static_arena_init,
|
||||||
|
growing_arena_init,
|
||||||
|
}
|
||||||
|
|
||||||
arena_temp_begin :: proc{
|
arena_temp_begin :: proc{
|
||||||
static_arena_temp_begin,
|
static_arena_temp_begin,
|
||||||
growing_arena_temp_begin,
|
growing_arena_temp_begin,
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ Growing_Arena :: struct {
|
|||||||
|
|
||||||
DEFAULT_MINIMUM_BLOCK_SIZE :: 1<<20 // 1 MiB should be enough
|
DEFAULT_MINIMUM_BLOCK_SIZE :: 1<<20 // 1 MiB should be enough
|
||||||
|
|
||||||
|
growing_arena_init :: proc(arena: ^Static_Arena, reserved: uint = DEFAULT_MINIMUM_BLOCK_SIZE) -> (err: Allocator_Error) {
|
||||||
|
arena.block = memory_block_alloc(0, reserved, {}) or_return
|
||||||
|
arena.total_used = 0
|
||||||
|
arena.total_reserved = arena.block.reserved
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
growing_arena_alloc :: proc(arena: ^Growing_Arena, min_size: int, alignment: int) -> (data: []byte, err: Allocator_Error) {
|
growing_arena_alloc :: proc(arena: ^Growing_Arena, min_size: int, alignment: int) -> (data: []byte, err: Allocator_Error) {
|
||||||
align_forward_offset :: proc "contextless" (arena: ^Growing_Arena, alignment: int) -> uint #no_bounds_check {
|
align_forward_offset :: proc "contextless" (arena: ^Growing_Arena, alignment: int) -> uint #no_bounds_check {
|
||||||
alignment_offset := uint(0)
|
alignment_offset := uint(0)
|
||||||
@@ -37,7 +44,7 @@ growing_arena_alloc :: proc(arena: ^Growing_Arena, min_size: int, alignment: int
|
|||||||
|
|
||||||
block_size := max(size, arena.minimum_block_size)
|
block_size := max(size, arena.minimum_block_size)
|
||||||
|
|
||||||
new_block := memory_block_alloc(block_size, block_size, {}) or_return
|
new_block := memory_block_alloc(size, block_size, {}) or_return
|
||||||
new_block.prev = arena.curr_block
|
new_block.prev = arena.curr_block
|
||||||
arena.curr_block = new_block
|
arena.curr_block = new_block
|
||||||
arena.total_reserved += new_block.reserved
|
arena.total_reserved += new_block.reserved
|
||||||
|
|||||||
Reference in New Issue
Block a user