package core:mem/virtual
Index
Variables (1)
Procedures (34)
- alloc_from_memory_block
- arena_alloc
- arena_allocator
- arena_allocator_proc
- arena_check_temp
- arena_destroy
- arena_free_all
- arena_growing_bootstrap_new_by_name
- arena_growing_bootstrap_new_by_offset
- arena_growing_free_last_memory_block
- arena_init_buffer
- arena_init_growing
- arena_init_static
- arena_static_bootstrap_new_by_name
- arena_static_bootstrap_new_by_offset
- arena_static_reset_to
- arena_temp_begin
- arena_temp_end
- arena_temp_ignore
- commit
- decommit
- make_aligned
- make_multi_pointer
- make_slice
- map_file_from_file_descriptor
- map_file_from_path
- memory_block_alloc
- memory_block_dealloc
- new
- new_aligned
- protect
- release
- reserve
- reserve_and_commit
Procedure Groups (4)
Types
Allocator_Error ¶
Allocator_Error :: runtime.Allocator_Error
Arena ¶
Arena :: struct { kind: Arena_Kind, curr_block: ^Memory_Block, total_used: uint, total_reserved: uint, default_commit_size: uint, // commit size <= reservation size minimum_block_size: uint, // block size == total reservation 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.
Related Procedures With Parameters
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 an 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
.
Related Procedures With Parameters
Related Procedures With Returns
Map_File_Error ¶
Map_File_Error :: enum int { None, Open_Failure, Stat_Failure, Negative_Size, Too_Large_Size, Map_Failure, }
Related Procedures With Returns
- map_file_from_file_descriptor
- map_file_from_path
- map_file (procedure groups)
Map_File_Flag ¶
Map_File_Flag :: enum u32 { Read, Write, }
Map_File_Flags ¶
Map_File_Flags :: distinct bit_set[Map_File_Flag; u32]
Related Procedures With Parameters
- map_file_from_file_descriptor
- map_file_from_path
- map_file (procedure groups)
Memory_Block ¶
Memory_Block :: struct { prev: ^Memory_Block, base: [^]u8, used: uint, committed: uint, reserved: uint, }
Related Procedures With Parameters
Related Procedures With Returns
Memory_Block_Flag ¶
Memory_Block_Flag :: enum u32 { Overflow_Protection, }
Memory_Block_Flags ¶
Memory_Block_Flags :: distinct bit_set[Memory_Block_Flag; u32]
Related Procedures With Parameters
Protect_Flag ¶
Protect_Flag :: enum u32 { Read, Write, Execute, }
Protect_Flags ¶
Protect_Flags :: distinct bit_set[Protect_Flag; u32]
Related Procedures With Parameters
Related Constants
Constants
DEFAULT_ARENA_GROWING_COMMIT_SIZE ¶
DEFAULT_ARENA_GROWING_COMMIT_SIZE :: 8 * mem.Megabyte
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(block: ^Memory_Block, min_size, alignment: uint, default_commit_size: uint = 0) -> (data: []u8, err: runtime.Allocator_Error) {…}
arena_alloc ¶
arena_alloc :: proc(arena: ^Arena, size: uint, alignment: uint, loc := #caller_location) -> (data: []u8, err: runtime.Allocator_Error) {…}
Allocates memory from the provided arena.
arena_allocator ¶
Create an Allocator
from the provided Arena
arena_allocator_proc ¶
arena_allocator_proc :: proc( 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 procedure used by an Allocator
produced by arena_allocator
arena_check_temp ¶
arena_check_temp :: proc(arena: ^Arena, loc := #caller_location) {…}
Asserts that all uses of Arena_Temp
has been used by an Arena
arena_destroy ¶
arena_destroy :: proc(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(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($T: typeid, $field_name: string = , minimum_block_size: uint = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}
Ability to bootstrap allocate a struct with an arena within the struct itself using the growing variant strategy.
arena_growing_bootstrap_new_by_offset ¶
arena_growing_bootstrap_new_by_offset :: proc($T: typeid, offset_to_arena: uintptr, minimum_block_size: uint = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}
Ability to bootstrap allocate a struct with an arena within the struct itself using the growing variant strategy.
arena_growing_free_last_memory_block ¶
arena_growing_free_last_memory_block :: proc(arena: ^Arena, loc := #caller_location) {…}
Frees the last memory block of a Growing Arena
arena_init_buffer ¶
arena_init_buffer :: proc(arena: ^Arena, buffer: []u8) -> (err: runtime.Allocator_Error) {…}
Initialization of an Arena
to be a .Buffer
variant.
A buffer arena contains single Memory_Block
created from a user provided []byte.
arena_init_growing ¶
arena_init_growing :: proc(arena: ^Arena, reserved: uint = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE) -> (err: runtime.Allocator_Error) {…}
Initialization of an Arena
to be a .Growing
variant.
A growing arena is a linked list of Memory_Block
s allocated with virtual memory.
arena_init_static ¶
arena_init_static :: proc(arena: ^Arena, reserved: uint = DEFAULT_ARENA_STATIC_RESERVE_SIZE, commit_size: uint = DEFAULT_ARENA_STATIC_COMMIT_SIZE) -> (err: runtime.Allocator_Error) {…}
Initialization of an Arena
to be a .Static
variant.
A static arena contains a single Memory_Block
allocated with virtual memory.
arena_static_bootstrap_new_by_name ¶
arena_static_bootstrap_new_by_name :: proc($T: typeid, $field_name: string = , reserved: uint) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}
Ability to bootstrap allocate a struct with an arena within the struct itself using the static variant strategy.
arena_static_bootstrap_new_by_offset ¶
arena_static_bootstrap_new_by_offset :: proc($T: typeid, offset_to_arena: uintptr, reserved: uint) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}
Ability to bootstrap allocate a struct with an arena within the struct itself using the static variant strategy.
arena_static_reset_to ¶
arena_static_reset_to :: proc(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(arena: ^Arena, loc := #caller_location) -> (temp: Arena_Temp) {…}
Begins the section of temporary arena memory.
arena_temp_end ¶
arena_temp_end :: proc(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(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 {…}
make_aligned ¶
make_aligned :: proc(arena: ^Arena, $T: typeid/[]T, #any_int len: int, alignment: uint, loc := #caller_location) -> (T, runtime.Allocator_Error) {…}
make_aligned
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.
Note: Prefer using the procedure group make
.
make_multi_pointer ¶
make_multi_pointer :: proc(arena: ^Arena, $T: typeid/[^]T, #any_int len: int, loc := #caller_location) -> ($/[^]T, runtime.Allocator_Error) {…}
make_multi_pointer
allocates and initializes a dynamic array. 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.
This is "similar" to doing raw_data(make([]E, len, allocator))
.
Note: Prefer using the procedure group make
.
make_slice ¶
make_slice :: proc(arena: ^Arena, $T: typeid/[]T, #any_int len: int, loc := #caller_location) -> (T, runtime.Allocator_Error) {…}
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.
Note: Prefer using the procedure group make
.
map_file_from_file_descriptor ¶
map_file_from_file_descriptor :: proc(fd: uintptr, flags: Map_File_Flags) -> (data: []u8, error: Map_File_Error) {…}
map_file_from_path ¶
map_file_from_path :: proc(filename: string, flags: Map_File_Flags) -> (data: []u8, error: Map_File_Error) {…}
memory_block_alloc ¶
memory_block_alloc :: proc(committed, reserved: uint, alignment: uint = 0, flags: Memory_Block_Flags = {}) -> (block: ^Memory_Block, err: runtime.Allocator_Error) {…}
memory_block_dealloc ¶
memory_block_dealloc :: proc(block_to_free: ^Memory_Block) {…}
new ¶
new :: proc(arena: ^Arena, $T: typeid, loc := #caller_location) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}
The new
procedure allocates memory for a type T
from a virtual.Arena
. The second argument is a type,
not a value, and the value return is a pointer to a newly allocated value of that type using the specified allocator.
new_aligned ¶
new_aligned :: proc(arena: ^Arena, $T: typeid, alignment: uint, loc := #caller_location) -> (ptr: ^typeid, err: runtime.Allocator_Error) {…}
The new_aligned
procedure allocates memory for a type T
from a virtual.Arena
with a specified alignment
.
The second argument is a type, not a value, and the value return is a pointer to a newly allocated value of
that type using the specified allocator.
protect ¶
protect :: proc "contextless" (data: rawptr, size: uint, flags: Protect_Flags) -> bool {…}
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 ¶
arena_growing_bootstrap_new :: proc{ arena_growing_bootstrap_new_by_offset, arena_growing_bootstrap_new_by_name, }
Ability to bootstrap allocate a struct with an arena within the struct itself using the growing variant strategy.
arena_static_bootstrap_new ¶
arena_static_bootstrap_new :: proc{ arena_static_bootstrap_new_by_offset, arena_static_bootstrap_new_by_name, }
Ability to bootstrap allocate a struct with an arena within the struct itself using the static variant strategy.
make ¶
make :: proc{ make_slice, make_multi_pointer, }
map_file ¶
map_file :: proc{ map_file_from_path, map_file_from_file_descriptor, }
Source Files
- arena.odin
- arena_util.odin
- file.odin
- virtual.odin
- virtual_platform.odin
- (hidden platform specific files)
Generation Information
Generated with odin version dev-2024-11 (vendor "odin") Windows_amd64 @ 2024-11-16 21:10:10.043284800 +0000 UTC