Embedded Artistry libmemory
Memory library for embedded systems (malloc and friends)
malloc.h File Reference
#include <stdlib.h>
Include dependency graph for malloc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void malloc_addblock (void *addr, size_t size)
 Assign blocks of memory for use by malloc(). More...
 
void malloc_init (void)
 Initialize Malloc. More...
 

Function Documentation

◆ malloc_addblock()

void malloc_addblock ( void *  addr,
size_t  size 
)

Assign blocks of memory for use by malloc().

Initializes the malloc() backend with a memory address and memory pool size. This memory is assumed to be owned by malloc() and is vended out when memory is requested. Multiple blocks can be added.

NOTE: This API must be called before malloc() can be used. If you call malloc() before allocating memory, malloc() will return NULL because there is no available memory to provide to the user.

Parameters
addrPointer to the memory block address that you are providing to malloc()
sizeSize of the memory block that you are providing to malloc()

malloc_addblock must be called before memory allocation calls are made. In this FreeRTOS implementation, malloc() calls will block until memory has been allocated

malloc_addblock must be called before memory allocation calls are made. In this ThreadX implementation, malloc() calls will block until memory has been allocated

Definition at line 9 of file malloc_framework_rtos.cpp.

10 {
11  os::Heap::addBlock(addr, size);
12 }

References align_up, ALLOC_HEADER_SZ, heap_region_cnt, heap_region_max, heap_regions, initialized_, malloc_pool_, alloc_node_t::node, and alloc_node_t::size.

◆ malloc_init()

void malloc_init ( void  )

Initialize Malloc.

Weakly linked, can be overridden based on your needs. Each malloc implementation contains a different set of initialization requirements