TLSF-based malloc.

TLSF-based global memory allocator.

This is a malloc/free implementation built on top of the TLSF allocator. It defines a global tlsf_control block and performs allocations on that block. This implemetation replaces the system malloc

Additionally, the calls to TLSF are wrapped in irq.h::irq_disable()/irq_restore(), to make it thread-safe.

If this module is used as the system memory allocator, then the global memory control block should be initialized as the first thing before the stdlib is used. Boards should use tlsf-malloc.h::tlsf_add_global_pool() at startup to add all the memory regions they want to make available for dynamic allocation via malloc.h::malloc().

void tlsf_size_walker(void * ptr, msp430_types.h::size_t size, int used, void * user)

Walk the memory pool to print all block sizes and to calculate the total amount of free and used block sizes.

Note

This function is passed to tlsf_walk_pool()

Parameters

ptr:Pointer to the current block.
size:Size of the current block at ptr.
used:Shows whether the current block is used or free.
user:Custom data expected to be of type pointer to tlsf_size_container_t

int tlsf_add_global_pool(void * mem, msp430_types.h::size_t bytes)

Add an area of memory to the global allocator pool.

The first time this function is called, it will automatically perform a tlsf_create() on the global tlsf_control block.

Parameters

mem:Pointer to memory area. Should be aligned to 4 bytes.
bytes:Size in bytes of the memory area.

Return values

  • 0 on success, nonzero on failure.
tlsf_t * _tlsf_get_global_control(void)

Get a pointer to the global tlsf_control block.

Use for debugging purposes only.

struct tlsf_size_container_t

Struct to hold the total sizes of free and used blocks Used for tlsf-malloc.h::tlsf_size_walker()

unsigned free

total free size

unsigned used

total used size