package core:mem/virtual

Types

Allocator_Error ¶

Allocator_Error :: runtime.Allocator_Error

Arena ¶

Arena :: struct {
	kind:               Arena_Kind,
	curr_block:         ^Memory_Block,
	total_used:         uint,
	total_reserved:     uint,
	minimum_block_size: uint,
	temp_count:         uint,
	mutex:              sync.Mutex,
}
 

Arena is a generalized arena allocator that supports 3 different variants.

Growing: A linked list of `Memory_Block`s allocated with virtual memory.
Static: A single `Memory_Block` allocated with virtual memory.
Buffer: A single `Memory_Block` created from a user provided []byte.

Arena_Kind ¶

Arena_Kind :: enum uint {
	Growing = 0, // Chained memory blocks (singly linked list).
	Static  = 1, // Fixed reservation sized.
	Buffer  = 2, // Uses a fixed sized buffer.
}

Arena_Temp ¶

Arena_Temp :: struct {
	arena: ^Arena,
	block: ^Memory_Block,
	used:  uint,
}
 

An Arena_Temp is a way to produce temporary watermarks to reset a arena to a previous state. All uses of an Arena_Temp must be handled by ending them with arena_temp_end or ignoring them with arena_temp_ignore.

Memory_Block ¶

Memory_Block :: struct {
	prev:      ^Memory_Block,
	base:      [^]u8,
	used:      uint,
	committed: uint,
	reserved:  uint,
}

Memory_Block_Flag ¶

Memory_Block_Flag :: enum u32 {
	Overflow_Protection, 
}

Memory_Block_Flags ¶

Memory_Block_Flags :: distinct bit_set[Memory_Block_Flag; u32]

Protect_Flag ¶

Protect_Flag :: enum u32 {
	Read, 
	Write, 
	Execute, 
}

Protect_Flags ¶

Protect_Flags :: distinct bit_set[Protect_Flag; u32]

Constants

DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE ¶

DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE :: DEFAULT_ARENA_STATIC_COMMIT_SIZE

DEFAULT_ARENA_STATIC_COMMIT_SIZE ¶

DEFAULT_ARENA_STATIC_COMMIT_SIZE :: mem.Megabyte
 

1 MiB should be enough to start with

DEFAULT_ARENA_STATIC_RESERVE_SIZE ¶

DEFAULT_ARENA_STATIC_RESERVE_SIZE :: mem.Gigabyte when size_of(uintptr) == 8 else 128 * mem.Megabyte
 

1 GiB on 64-bit systems, 128 MiB on 32-bit systems by default

Protect_No_Access ¶

Protect_No_Access :: Protect_Flags{}

Variables

DEFAULT_PAGE_SIZE ¶

DEFAULT_PAGE_SIZE: uint = …

Procedures

alloc_from_memory_block ¶

alloc_from_memory_block :: proc "odin" (block: ^Memory_Block, min_size, alignment: uint) -> (data: []u8, err: runtime.Allocator_Error) {…}

arena_alloc ¶

arena_alloc :: proc "odin" (arena: ^Arena, size: uint, alignment: uint, loc := #caller_location) -> (data: []u8, err: runtime.Allocator_Error) {…}

arena_allocator ¶

arena_allocator :: proc "odin" (arena: ^Arena) -> runtime.Allocator {…}

arena_allocator_proc ¶

arena_allocator_proc :: proc "odin" (
	allocator_data:  rawptr, 
	mode:            runtime.Allocator_Mode, 
	size, alignment: int, 
	old_memory:      rawptr, 
	old_size:        int, 
	location := #caller_location, 
) -> (data: []u8, err: runtime.Allocator_Error) {…}
 

The allocator procedured by an Allocator produced by arena_allocator

arena_check_temp ¶

arena_check_temp :: proc "odin" (arena: ^Arena, loc := #caller_location) {…}
 

Asserts that all uses of Arena_Temp has been used by an Arena

arena_destroy ¶

arena_destroy :: proc "odin" (arena: ^Arena, loc := #caller_location) {…}
 

Frees all of the memory allocated by the arena and zeros all of the values of an arena. A buffer based arena does not delete the provided []byte bufffer.

arena_free_all ¶

arena_free_all :: proc "odin" (arena: ^Arena, loc := #caller_location) {…}
 

Deallocates all but the first memory block of the arena and resets the allocator's usage to 0.

arena_growing_bootstrap_new_by_name ¶

arena_growing_bootstrap_new_by_name :: proc "odin" ($T: typeid, $field_name: string = , minimum_block_size: uint = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}

arena_growing_bootstrap_new_by_offset ¶

arena_growing_bootstrap_new_by_offset :: proc "odin" ($T: typeid, offset_to_arena: uintptr, minimum_block_size: uint = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}

arena_growing_free_last_memory_block ¶

arena_growing_free_last_memory_block :: proc "odin" (arena: ^Arena, loc := #caller_location) {…}
 

Frees the last memory block of a Growing Arena

arena_init_buffer ¶

arena_init_buffer :: proc "odin" (arena: ^Arena, buffer: []u8) -> (err: runtime.Allocator_Error) {…}

arena_init_growing ¶

arena_init_growing :: proc "odin" (arena: ^Arena, reserved: uint = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE) -> (err: runtime.Allocator_Error) {…}

arena_init_static ¶

arena_init_static :: proc "odin" (arena: ^Arena, reserved: uint, commit_size: uint = DEFAULT_ARENA_STATIC_COMMIT_SIZE) -> (err: runtime.Allocator_Error) {…}

arena_static_bootstrap_new_by_name ¶

arena_static_bootstrap_new_by_name :: proc "odin" ($T: typeid, $field_name: string = , reserved: uint) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}

arena_static_bootstrap_new_by_offset ¶

arena_static_bootstrap_new_by_offset :: proc "odin" ($T: typeid, offset_to_arena: uintptr, reserved: uint) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}

arena_static_reset_to ¶

arena_static_reset_to :: proc "odin" (arena: ^Arena, pos: uint, loc := #caller_location) -> bool {…}
 

Resets the memory of a Static or Buffer arena to a specific position (offset) and zeroes the previously used memory.

arena_temp_begin ¶

arena_temp_begin :: proc "odin" (arena: ^Arena, loc := #caller_location) -> (temp: Arena_Temp) {…}

arena_temp_end ¶

arena_temp_end :: proc "odin" (temp: Arena_Temp, loc := #caller_location) {…}
 

Ends the section of temporary arena memory by resetting the memory to the stored position.

arena_temp_ignore ¶

arena_temp_ignore :: proc "odin" (temp: Arena_Temp, loc := #caller_location) {…}
 

Ignore the use of a arena_temp_begin entirely by __not__ resetting to the stored position.

commit ¶

commit :: proc "contextless" (data: rawptr, size: uint) -> runtime.Allocator_Error {…}

decommit ¶

decommit :: proc "contextless" (data: rawptr, size: uint) {…}

memory_block_alloc ¶

memory_block_alloc :: proc "odin" (committed, reserved: uint, flags: Memory_Block_Flags) -> (block: ^Memory_Block, err: runtime.Allocator_Error) {…}

memory_block_dealloc ¶

memory_block_dealloc :: proc "odin" (block_to_free: ^Memory_Block) {…}

protect ¶

protect :: proc "contextless" (data: rawptr, size: uint, flags: Protect_Flags) -> bool {…}

release ¶

release :: proc "contextless" (data: rawptr, size: uint) {…}

reserve ¶

reserve :: proc "contextless" (size: uint) -> (data: []u8, err: runtime.Allocator_Error) {…}

reserve_and_commit ¶

reserve_and_commit :: proc "contextless" (size: uint) -> (data: []u8, err: runtime.Allocator_Error) {…}

Procedure Groups

arena_growing_bootstrap_new ¶

 

Ability to bootstrap allocate a struct with an arena within the struct itself using the growing variant strategy.

arena_static_bootstrap_new ¶

 

Ability to bootstrap allocate a struct with an arena within the struct itself using the static variant strategy.

Source Files

Generation Information

Generated with odin version dev-2023-03 (vendor "odin") Windows_amd64 @ 2023-03-29 21:09:05.438236000 +0000 UTC