Reserves reserve bytes of address space for the pool, rounded up to a whole number of pages, and starts it empty.
#import "Flat_Pool";
A bump allocator over one contiguous range of reserved address space.
Procedures#
Returns nbytes bytes aligned to the pool's alignment, initializing the pool first if needed, or null if the OS refuses to commit the pages.
Rewinds the pool so the next get starts at the beginning; the committed pages stay committed.
Returns the whole reservation to the OS and leaves the pool uninitialized, so a later get starts over. Safe on a pool that never allocated.
The Allocator_Proc for a flat pool: use it as Allocator.{ flat_pool_allocator_proc, *pool }.
A small demonstration: initialize, allocate, reset with overwrite, finalize. It exists as a smoke test and is not part of the API.
Types#
A bump allocator over one contiguous range of reserved address space, committed page by page as it is used.
pool: Flat_Pool;
init(*pool, 1024 * 1024);
defer fini(*pool);
first := cast(*int) get(*pool, size_of(int));
first.* = 7;
for 0..9999 get(*pool, 64); // growing never moves `first`
assert(first.* == 7);
reset(*pool);
assert(get(*pool, size_of(int)) == first); // the same memory comes backDoesn't run in the browser (skipped on wasm).