Simple usage of Pool
memory allocator to automatically free memory of a code block:
#import "Basic";
Pool :: #import "Pool";
pool :: (code: Code) #expand {
_pool: Pool.Pool;
Pool.set_allocators(*_pool);
{
push_allocator(Pool.pool_allocator, *_pool);
#insert code;
}
print("The pool contains % bytes.\n", _pool.memblock_size - _pool.bytes_left);
print("Releasing the pool now.\n");
Pool.release(*_pool);
}
Can be used via
x: string; // define variables that need to out-live the pool outside
pool(#code {
// your code here
x = "some allocated data";
});
print(x);