allocator
struct Allocator
Members:
addr alloc
(function pointer:usize sz -> addr address
)addr realloc
(function pointer:addr address, usize sz -> addr address
)addr free
(function pointer:addr address
)
a_alloc
Parameters: ptr Allocator allocator, usize sz
Returns: addr address
Calls the alloc function on the given allocator, and throws if this method is not implemented
a_realloc
Parameters: ptr Allocator allocator, addr address, usize sz
Returns: addr address
Calls the realloc function on the given allocator, and throws if this method is not implemented
a_free
Parameters: ptr Allocator allocator, addr address
Calls the free function on the given allocator, and throws if this method is not implemented
struct HeapAllocator
Inherits from Allocator
, is used for allocating on the heap
Only exists if the Heap
version is enabled
struct BlockAllocator
Inherits from Allocator
, is used for allocating in a buffer
Members:
usize blockSize
- The size of each blockusize blockCount
- The amount of blocks the buffer hasaddr allocatedBlocks
- The bit array of allocated blocksaddr buffer
- The buffer to allocate from
block_allocator_init
Parameters: ptr BlockAllocator allocator, usize blockSize, usize blockCount, addr allocatedBlocks, addr buffer
Initializes a block allocator allocatedBlocks points to ceil(blockCount / 8) bytes of memory to keep track of blocks that have been allocated buffer points to blockSize * blockCount bytes of memory
struct ArenaAllocator
Inherits from Allocator
, is used as an arena allocator
Members:
addr buffer
- pointer to the buffer to allocate memory fromusize bufferSize
- size of the bufferusize offset
- offset of the next block to be allocated
arena_allocator_init
Parameters: ptr BlockAllocator allocator, addr buffer, usize bufferSize
Initializes an arena allocator