Packages

builtin
cbindgen
core
core.alloc
core.alloc.arena
core.alloc.atomic
core.alloc.debug
core.alloc.fixed
core.alloc.gc
core.alloc.heap
core.alloc.log
core.alloc.memwatch
core.alloc.pool
core.alloc.ring
core.arg_parse
core.array
core.avl_tree
core.bucket_array
core.conv
core.crypto
core.crypto.keys
core.doc
core.encoding
core.encoding.base64
core.encoding.csv
core.encoding.hex
core.encoding.json
core.encoding.kdl
core.encoding.osad
core.encoding.utf8
core.encoding.xml
core.hash
core.hash.md5
core.hash.sha1
core.hash.sha256
core.heap
core.intrinsics
core.intrinsics.atomics
core.intrinsics.onyx
core.intrinsics.types
core.intrinsics.wasm
core.io
core.io.binary
core.iter
core.js
core.list
core.map
core.math
core.memory
core.misc
core.net
core.os
core.random
core.set
core.slice
core.string
core.sync
core.test
core.thread
core.time
main
runtime
runtime.info
runtime.platform
runtime.vars
simd

package core.alloc.arena

This allocator is mostly used for making many fixed-size allocation (i.e. allocations that will not need to change in size, such as game entities or position structs). The power of this allocator over the heap allocator for this purpose is that it is much faster, since the logic is simpler. Another power of this allocator over something such as a dynamic array is that the dynamic array could relocate and cause any pointers to the data inside to become invalidated; this is definitely not behaviour you want. This arena allocator can grow as large as needed, while guaranteeing that the memory inside of it will never move.

Arena
Arena :: struct {
    backing_allocator: Allocator
    first_arena: &ArenaBlock
    current_arena: &ArenaBlock
    size: u32
    arena_size: u32
}

Stores internal details used during arena allocations.

auto
auto :: macro (size, $dest: Code) -> void
auto :: macro (body: Code, size: i32) -> i32

Creates an arena allocator and automatically applies it to the context's allocator in the current scope.

foo :: () {
    alloc.arena.auto();

    // Lazily allocate everything, knowing that it will
    // be freed when this function returns.
    for 100 {
        s := string.copy("Make a copy of me!");
    }
}
auto_temp
auto_temp :: macro (body: Code) -> i32

Creates an arena allocator to be used as the temporary allocator in the code block.

foo :: () {
    alloc.arena.auto_temp() {
        for 1000 {
            // Will be automatically freed
            x := new_temp(i32);
        }
    }
}
clear
clear :: (arena: &Arena) -> void

Clears and frees every page, except for first page.

free
free :: (arena: &Arena) -> void

Frees all pages in an arena.

get_allocated_arenas
get_allocated_arenas :: (arena: &Arena) -> u32

Returns the number of pages in the arena.

get_allocated_bytes
get_allocated_bytes :: (arena: &Arena) -> u32

Returns the number of bytes used by the arena.

make
make :: (backing: Allocator, arena_size: u32) -> Arena

Makes a new arena.

arena_size specifies the size of each individual arena page, which must be at least 4 bytes in size (but should be quite a bit large).

make_allocator
make_allocator :: (rs: &Arena) -> Allocator