Pool Allocator

#import "std/pool"

Pool allocator is simple growing allocator grouping all allocated memory into memory blocks of POOL_DEFAULT_SIZE bytes by default.

Supported Operations

- [x] Allocate
- [-] Reallocate (Always allocates and copy data into a new block.)
- [-] Free (Keeps memory for later use.)
- [x] Release
- [x] Reset


This allocator is used as a default temporary allocator in the application context.


POOL_DEFAULT_SIZE : usize : 65536

File: pool.bl


PoolAllocator :: struct {
    block_size: usize;
    allocator: *Allocator;
    used_blocks: [..]*u8;
    unused_blocks: [..]*u8;
    obsolete_blocks: [..]*u8;
    current_block: *u8;
    top: *u8;
    space: usize;

Pool allocator type.


File: pool.bl


pool_default :: 

Default pool allocator instance using the current allocator in application context and POOL_DEFAULT_SIZE.

File: pool.bl


pool_make :: fn (allocator : *Allocator: null, block_size :: POOL_DEFAULT_SIZE) PoolAllocator #inline

Make new pool allocator instance. The allocator is the allocator used internally to allocate block memory. The block_size is size of each preallocated block in Bytes (note that the block size can grow over time when bigger continuous memory allocations are required).

File: pool.bl


pool_release :: fn (pool: *PoolAllocator) 

Release all allocated memory used by pool (allocated in pool.allocator).

File: pool.bl


pool_reset :: fn (pool: *PoolAllocator)  #inline

Invalidate all allocations but keep preallocated memory block for later use.

File: pool.bl