TLSF-based malloc.

TLSF-based global memory allocator. More...

Detailed Description

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_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_add_global_pool() at startup to add all the memory regions they want to make available for dynamic allocation via malloc().

Files

file  tlsf-malloc.h
 TLSF-based global memory allocator.
 

Data Structures

struct  tlsf_size_container_t
 Struct to hold the total sizes of free and used blocks Used for tlsf_size_walker() More...
 

Functions

void tlsf_size_walker (void *ptr, 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. More...
 
int tlsf_add_global_pool (void *mem, size_t bytes)
 Add an area of memory to the global allocator pool. More...
 
tlsf_t * _tlsf_get_global_control (void)
 Get a pointer to the global tlsf_control block. More...
 

Function Documentation

◆ _tlsf_get_global_control()

tlsf_t* _tlsf_get_global_control ( void  )

Get a pointer to the global tlsf_control block.

Use for debugging purposes only.

◆ tlsf_add_global_pool()

int tlsf_add_global_pool ( void *  mem,
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.

Warning
If this module is used, then this function MUST be called at least once, before any allocations take place.
Parameters
memPointer to memory area. Should be aligned to 4 bytes.
bytesSize in bytes of the memory area.
Returns
0 on success, nonzero on failure.

◆ tlsf_size_walker()

void tlsf_size_walker ( void *  ptr,
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
ptrPointer to the current block.
sizeSize of the current block at ptr.
usedShows whether the current block is used or free.
userCustom data expected to be of type pointer to tlsf_size_container_t