Module Tolk.Tlsf
Two-Level Segregated Fit allocator.
Manages a contiguous address range with O(1) best-fit allocation and O(1) deallocation with coalescing. Free blocks are indexed by two levels of buckets:
- Level 1 is the most significant bit of the block size.
- Level 2 subdivides each L1 range into
2{^l2_cnt}entries.
Allocation finds the smallest free block that fits, splitting the remainder. Deallocation merges the freed block with its neighbours.
Types
Constructors
val create :
size:int ->
?base:int ->
?block_size:int ->
?lv2_cnt:int ->
unit ->
tcreate ~size ?base ?block_size ?lv2_cnt () is a TLSF allocator managing size bytes starting at virtual address base.
base defaults to 0. block_size is the minimum allocation granularity and defaults to 16. lv2_cnt is the number of level-2 subdivisions per level-1 bucket and defaults to 16.
Operations
val alloc : t -> int -> ?align:int -> unit -> intalloc t size ?align () is the start address of a newly allocated region of size bytes. The returned address is a multiple of align.
align defaults to 1. The actual allocation is at least block_size bytes.
Raises Out_of_memory if no free block can satisfy the request.