This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to configure the alignment parameter for heap multi-buf

I have a few question regarding to the "align" parameter for heap multi-buf:

1. For Cortex-M3 core, does it mean the "align" has a unit of 1 byte?

2. If I would like the heap to start with an even address, should I configure the align to 2 or something else?

3. Cortex-M3's address has 32 bits, does it mean we need to configure "align" to 4?

4. When the heap is configured with some alignment other then 0, can we still request memory_alloc with 0 align?

5. Could you provide some example or use cases with different alignment configuration?

Thanks.

  • Hi Thomas,

    1. Yes

    2. An alignment of 2 means even addresses. Note that HeapMultiBuf is a collection of HeapBufs, each HeapBuf manages a buffer, and the align parameter in HeapBuf_Params for each buffer in the HeapMultiBuf determines the alignment of each block in the buffer. If you dynamically create the HeapMultiBuf, you are responsible for providing buffers that are aligned to match the align parameter for each HeapBuf. See the HeapBuf_Params documentation for details.

    3. The M3 is 8-bit-byte-addressable, so I don't think there is any restriction at that level.

    4. Allocation from a HeapMultiBuf will return a block from the first buffer which has: a) a block size that is >= to the requested size AND b) an alignment that is >= to the requested alignment. So if Memory_alloc() is invoked with an argument of align=0, that simply means it will return a block from the first buffer that fulfills the block size requirement.

    5. HeapMultiBuf is useful when you have algorithms/peripherals that work with buffers of different alignment in a system. For example, the DMA might be more efficient when dealing with 32-bit aligned buffers, whereas an image encoder might want buffers that are aligned to the size of macroblocks. You want the ability to allocate buffers of various alignment while keeping fragmentation in check and minimizing wasted space.

    Best regards,
    Vincent
  • Thanks for the detail and quick responds.