Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 35 Next »

Memory segments API has been introduced with µC/LIB v1.38. They offer the possibility to create segments of memory at different locations and to allocate buffers from them.  

Three different functions are available to allocate memory from a memory segment:

FunctionDescriptionUse case
Mem_SegAlloc()General-purpose allocation function. It will provide a buffer aligned on a CPU word boundary and with no guaranteed padding.General purpose buffers and control data accessed only by the CPU.
Mem_SegAllocExt()Same as Mem_SegAlloc(), except that this function allows specifying an alignment. It will also provide the amount of bytes required to prevent overflow when the memory segment's size limit is exceeded.General purpose buffers and control data accessed only by the CPU but that require specific alignment (for example, task stacks).
Mem_SegAllocHW()Allocates a buffer using specified alignment. This function will also add padding at the end of the buffer according to the padding_align argument specified at the creation of the memory segment. This is particularly useful on systems that use cache memory as it allows to have nothing else than the buffer mapped on a cache line.Data buffers that can be copied via a DMA engine.

Example usage of memory segments

gives an example usage of memory segments. In this example, we attempt to create a memory segment and to allocate three buffers of 20 bytes from it using the three different segment allocation functions available. Following the listing is an explanation of the differences between these three buffers. 

  • No labels