Training
×

Local Memory - “C” Library Heap Functions

If the goal is to share memory between threads of the same RT process, the C functions malloc and free can provide dynamic memory to a thread, which creates the data area, fills it, and releases the dynamic memory area when no longer in use. This type of memory is aligned on a 16-byte boundary.
The pointer to the dynamic memory area can be made global for the process or can be passed to another thread in the same process via a data mailbox. Although this pointer could be passed to a thread in another process, it can not be used in that context.
Note that free returns the memory to the C library free space, but not to the process memory pool! Such memory is only available for further mallocs. Use heap_compact to return freed memory blocks to the process’s memory pool. If a process is deleted, all memory is returned to its parent process and available for other use.
 
The “C” library heap functions are implemented with native INtime functions for heap management and heap debugging. A heap itself is implemented using mpools.
There are various ways of debugging heap memory problems, so as overwriting after free, and memory leaks. See the sample projects installed with the SDK, specifically the “Memory Heap Debug Sample”.