optimise raw allocator make allocators use new spec remove redundant `lily.` prefix from lily tests kill SimpleAllocator (nobody liked it)
1.1 KiB
1.1 KiB
allocators
Tip
well designed allocators should ensure they only deallocate or reallocate allocations they made.
- all spec compliant allocators should implement:
unless otherwise stated, functions can be optionally inline.
names of arguments are up to programmer discretion.
names and signature of functions must be identical to shown below.
Allocator := struct {
new := fn(): Self
/// prepare to be deallocated.
deinit := fn(self: ^Self): void
/// should return null on failure.
/// should dealloc any intermediate allocations on failure.
alloc := fn(self: ^Self, $T: type, count: uint): ?[]T
/// same behaviour as alloc, except:
/// must be zeroed.
alloc_zeroed := fn(self: ^Self, $T: type, count: uint): ?[]T
/// same behaviour as alloc, except:
/// must move data to new allocation,
/// must ensure the old allocation is freed at some point.
realloc := fn(self: ^Self, $T: type, ptr: ^T, new_count: uint): ?[]T
/// must dealloc or schedule the freeing of the given allocation
dealloc := fn(self: ^Self, $T: type, ptr: ^T): void
}