core/mem/tlsf

mem_tlsf

Types

4

Allocator

Allocator :: struct { // Empty lists point at this block to indicate they are free. block_null: Block_Header, // Bitmaps for free lists. fl_bitmap: u32, sl_bitmap: [FL_INDEX_COUNT]u32, // Head of free lists. blocks: [FL_INDEX_COUNT][SL_INDEX_COUNT]^Block_Header, // Keep track of pools so we can deallocate them. // If `pool.allocator` is blank, we don't do anything. // We also use this linked list of pools to report // statistics like how much memory is still available, // fragmentation, etc. pool: Pool, // If we're expected to grow when we run out of memory, // how much should we ask the backing allocator for? new_pool_size: uint, }Source

Block_Header

Block_Header :: struct { prev_phys_block: ^Block_Header, size: uint, // Next and previous free blocks. next_free: ^Block_Header, prev_free: ^Block_Header, }Source

Block header structure.

There are several implementation subtleties involved:

  • The prev_phys_block field is only valid if the previous block is free.
  • The prev_phys_block field is actually stored at the end of the
previous block. It appears at the beginning of this structure only to
	simplify the implementation.
- The `next_free` / `prev_free` fields are only valid if the block is free.

Error

Error :: enum u8 { None = 0, Invalid_Backing_Allocator = 1, Invalid_Alignment = 2, Backing_Buffer_Too_Small = 3, Backing_Buffer_Too_Large = 4, Backing_Allocator_Error = 5, }Source

Constants

14

BLOCK_HEADER_FREE

BLOCK_HEADER_FREE :: uint = uint(1 << 0)Source

Since block sizes are always at least a multiple of 4, the two least significant bits of the size field are used to store the block status:

  • bit 0: whether block is busy or free
  • bit 1: whether previous block is busy or free

Procedures

11

Procedure Groups

2

Reference search

Find anything

Documentation preferences

Settings

System theme variants

Used only while Theme is set to System.