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.

HeapMem_Alloc always fails with out of memory error

Other Parts Discussed in Thread: SYSBIOS

Hi,

I am trying to do something very simple but for some reason it just does not want to work:  I create a new HeapMem instance in my .cfg file:

var heapMemDDRParams = new HeapMem.Params();
heapMemDDRParams.instance.name = "heapMemDDR";
heapMemDDRParams.size = 65536;
Program.global.heapMemDDR = HeapMem.create(heapMemDDRParams);

In my C code I try to use this heap to allocate memory (from within a task):

 Error_Block eb;
 Memory_Stats ms;

 HeapMem_getStats(heapMemDDR, &ms);
 Error_init(&eb); 
 pBuffer = (uint32_t *)HeapMem_alloc(heapMemDDR, 0x0004, 0, &eb);

The HeapMem_alloc always fails with an out of memory error message - no matter how many bytes a try to allocate.  I have added the "getState" to verify that the heap exists and that it has the right size.  Stepping though the code I can see that the heap exists and has the correct size.  Looking through ROV I can see the heap instance, the size is correct and the amount of free memory (equals to the size).  I can see that space for the heap has been reserved in the .far segment.  Everything looks right - but the allocate never succeeds. 

Any ideas what I am doing wrong? 

I have the following header files included in the C program:

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/heaps/HeapMem.h>
#include <xdc/runtime/Memory.h>
#include <xdc/runtime/Error.h>
#include <xdc/cfg/global.h>

I use SysBios 6.32.05.54.  I use CCS4.2.4.00033.  My target is a TMS320C6A8168 (DSP core).

Regards,

Niki

 

  • Hi Niki,

    Can you change the alignment to 1 instead of 0? 

    pBuffer = (uint32_t *)HeapMem_alloc(heapMemDDR, 0x0004, 1, &eb);

    Generally people go through the Memory module to access a heap. Alignment of 0 and 1 are same (don't care vs 1 MAU), but the Memory module converts a zero to a one so the individual heap implementations don't have to worry about converting zero to one. The heap might be messing up some logic with the zero value. [Big disclaimer...I don't have access to the code baseline right now...I'll confirm this when I get access].

    Todd

  • Hi Todd,

    The allignment of 1 seems to work - thanks! 

    I have tried using the Memory module (i.e.

    pBuffer = (uint32_t *)Memory_alloc(heapMemDDR, 0x0004, 0, &eb);

    But then I get the linker error:

    argument of type "ti_sysbios_heaps_HeapMem_Handle" is incompatible with parameter of type "xdc_runtime_IHeap_Handle" MyPacketizer main.cpp

    Should I cast the heapMemDDR handle to the xdc_runtime_IHeap_Handle type?  Is this safe to do?

    Regards,

    Niki

     

     

     

    l

  • Hi,

    I seem to have found the correct macro to do the cast:

    HeapMem_Handle_to_xdc_runtime_IHeap()

    Thanks!,

    Niki

     

  • Niki,

    HeapMem_Handle_upCast() looks a nicer (I think :)) and does the same thing.

    I verified that an alignment of zero is not a good thing to do with HeapMem_alloc.

    Correction on my part: specifying an alignment of zero and one is different. An alignment of zero means to use the default alignment (determined by the maximum alignment required by all data types). An alignment of one means to align on a MAU (or basically no alignment requirement). Certain heap implementations impose their own alignment requirements (e.g. needed for the specific implementation of the heap).

    Todd

  • Hi Todd,

     

    Thanks for the info and effort! 

    Regards,

    Niki