Packages

builtin
cbindgen
core
core.alloc
core.alloc.arena
core.alloc.atomic
core.alloc.fixed
core.alloc.gc
core.alloc.heap
core.alloc.log
core.alloc.memdebug
core.alloc.pool
core.alloc.ring
core.arg_parse
core.array
core.avl_tree
core.bucket_array
core.conv
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.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.pool

A pool allocator is an O(1) allocator that is capable of allocating and freeing. It is able to do both in constant time because it maintains a linked list of all the free elements in the pool. When an element is requested the first element of linked list is returned and the list is updated. When an element is freed, it becomes the first element. The catch with this strategy however, is that all of the allocations must be of the same size. This would not be an allocator to use when dealing with heterogenous data, but when doing homogenous data, such as game entities, this allocator is great. It allows you to allocate and free as many times as you want, without worrying about fragmentation or slow allocators. Just make sure you don't allocate more than the pool can provide.

PoolAllocator
PoolAllocator :: struct (Elem: type_expr) {
    buffer: [] Elem;
    first_free: &Elem;
}
Methods
PoolAllocator.alloc
PoolAllocator.alloc :: (pool: &PoolAllocator($Elem)) -> &Elem
PoolAllocator.free
PoolAllocator.free :: (pool: &PoolAllocator($Elem), elem: &Elem) -> void
make
make :: (buffer: [] $Elem) -> PoolAllocator(Elem)
make_allocator
make_allocator :: (pool: &PoolAllocator($Elem)) -> Allocator
pool_alloc
pool_alloc :: (pool: &PoolAllocator($Elem)) -> &Elem
pool_allocator_proc
pool_allocator_proc :: (pool: &PoolAllocator($Elem), aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr
pool_free
pool_free :: (pool: &PoolAllocator($Elem), elem: &Elem) -> void