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.

Memory Allocation for "new" C6748

Hello,

I have some code that is setup for dynamic memory allocation and it uses "new" in this fashion:

   t_s32* p_rx_samples = new(nothrow) t_s32[tx_sample_count];

Early in the program "new"  and "delete" are successfully used for a smaller memory segment.

In the sample case above the size of memory is large. I have a large heap allocated in external memory, and when I look at the available memory in DSP/BIOS there should be enough, however the memory location is in DDR (external) RAM and I am wondering whether "new" might be trying to allocate in local memory (which would not be adequate in size for this particular call). If this is the case, is there a way to ensure that "new" makes use of external memory?

Thanks in advance.

Dan.

 

 

 

  • Dan,

    Is your program a C++ program?  I'm just wondering why you're using new to allocate your array.

    Have you tried using the MEM module API for allocating memory?

    MEM_alloc(segid, size, align)

    This API allows you to select which MEM segment to allocate from via the segid parameter.  So, you could use this API to allocate your array from DDR.

    Also, please note that you'll need to use the configuration tool in order to create a heap in DDR memory segment.  If you need help with this, I can do that.

    Steve

  • Hi Steve,

    Thanks for your help.

    I am porting over code, some of which was written for a Windows console application. The code is  mixed C++ and C. Some calls at the low level written for CCS do use the Bios calls like MEM_alloc while calls like "new" are also present. I have used the DSP/BIOS configuration tool to make heaps in all sections of memory. I should probably convert over the "new" calls to MEM_allocs?

    One question I have is whether the heap that is allocated with the configuration tool is the only one available to these memory calls like, MEM_alloc or does it use memory outside of the configuration-heap?

  • DanB,

    I've discussed your situation with another team member, and he helped me to get a better understanding of your situation.  In short, you do not need to convert your 'new' calls to be 'MEM_alloc()' calls.

    Behind the scenes, all of the calls that use 'new' in your program will be directed to call malloc(), which in turn will just call MEM_alloc().  So, you can use the configuration tool to configure which MEM segment's heap you want 'new' calls to use by specifying the MEM segment for malloc() calls to be your external memory.

    To do all of this, you should follow these steps:

    1. You need to ensure that you've created a heap in DDR, and that the heap that you've created is large enough to handle all of your dynamic memory allocation needs.  Do this by opening up the properties of the DDR memory segment in the BIOS configuration tool.  Check the box to "enable heap in this memory" and specify a heap size that is appropriate for your needs:

    2.  Bring up the MEM manager properties of your *.tcf file using the BIOS configuration tool.  Specify your external memory segment "DDR" for "Segment For malloc / free()".  See below screen:

     

     

    Hope this helps,

    Steve

  • Hi Steve,

    Thanks for the suggestion. I have already done this, but in this instance, if I try to use "new" this generates a memory allocation error, whereas if I use MEM_alloc it does not.

    The two calls were:

    (Doesn't work:)

    t_s32* p_rx_samples = new(nothrow) t_s32[tx_sample_count];

     

    and (Does Work)

    p_rx_samples = (t_s32 *) MEM_alloc(DDR, (tx_sample_count*4), 4);

    The memory was avaliable, but could not be allocated through new.  I tried moving around the definition of p_rx_samples out of main in case this was causing a problem, but it didn't seem to matter. New has been used elsewhere without (reported) error. 

    It is good to know that the configuration setting should at least be the key to locating memory for "new", even if there may be other issues.

    Dan.

     

     

  • Hi Steve,

    Sorry!!! My bad...

    Upon re-examination, I did not have the malloc / free assigned to DDR (it was assigned to L3_CBS_RAM). I made the assignment in configuration and then "new" ran correctly.

    Thanks!

     

    dan.

  • Dan,

    No worries, glad to know that you've gotten past this issue!

    Steve