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.

Help with Memory_alloc

Hi,

I have some questions about Memory_alloc.I'd be glad if someone can help me.

The Memory_alloc function is:

Memory_alloc(IHeap_Handle heap, SizeT size, SizeT align, Error_Block *eb);

So my questions are:

1 - Why should I use Memory_alloc instead of C's malloc? What's the advantage of doing this?

2 - The third parameter (SizeT align) is measured in bits or bytes? Suppose I want a 32 bit aligned vector, the align parameter will be 32 or 4?

3 - How do I create and specify which heap I'm using. Until now I've managed to create a heap in MSMCSRAM or DDR3 and make it as default heap, so I can pass 0 or NULL as first parameter in Memory_alloc call. But suppose I want two heaps, one in L2SRAM and other in DDR3, how do I create the heaps and specify which one I should use when allocate memory? Is it possible?

Thanks for any help

  • Johannes,
    this page contains a detailed description of the module xdc.runtime.Memory and its usage. You can find answers to some of your questions there, but here is also a quick ...

    1. Memory_alloc allows you to write your C code once, and then choose a different memory manager in your config script without changing your C code. If you want to use C's malloc, you can select xdc.runtime.HeapStd as your app's memory manager.

    2. Alignments is given in MADUs (minimum addressable data units), which means bytes in most cases. Here is the doc for Memory_alloc: http://rtsc.eclipse.org/cdoc-tip/xdc/runtime/Memory.html#alloc.

    3. There are examples in the first linked page. If you created heaps statically (in your CFG script), the relevant CFG script example is this one. You can create multiple heaps, assign them to Program.global using any valid C identifier (myHeap1, myHeap2, etc.). Then, in your C code just add
    #include <xdc/cfg/global.h>
    and use myHeap1 and myHeap2 as a first argument for Memory_alloc.

     If you are creating heaps dynamically, see this example.

     

  • Hi, Sasha

    Thanks for your answer, the links are pretty usefull.

    Regards

    Johannes