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.

failed to allocate using malloc - 6678



Hi!

I am working on 6678 multicore processor.

I want to compare the memory overhead caused when data is allocated in shared memory and DDR3 .

I used malloc to allocate an array. but the allocation failed. still the code runs till the end.

Here is my code:

#include <stdio.h>
#include <stdlib.h>

void main(void)
{
int i,j;
short * IpBuffer;
IpBuffer = (short *)malloc(512*512*sizeof(short));

for (i=0; i<5000;i++)
{
for (j=0;j<5000;j++)
{

*(IpBuffer +i+2) = *(IpBuffer + i)+ *(IpBuffer + i+1);
*(IpBuffer +2*i+2) = *(IpBuffer + 2*i)+ *(IpBuffer +3* i+1);
*(IpBuffer +3*i+2) = *(IpBuffer + 3*i)+ *(IpBuffer + 2*i+1);
*(IpBuffer +2*i+1) = *(IpBuffer + 2+i)+ *(IpBuffer +3* i+1);
}

}

}

As per my knowledge malloc allocates array in heap, but in the cmd file I have not specified where this heap should be allocated. How can that be specified?

I tried with .sysmem and .data extensions, but it did'nt work.

Also, how can I ensure that code is compiled in debug mode

regards,

Sohal

  • Hi Sohal,

    I noticed that you want to malloc a space of 0x80000, so do you denote the -heap statement in your cmd file like

    -heap 0x80000

    of course the figure should be more than 0x80000 for safety.

    And the default allocation of heap section is decided by .sysmem, when the malloc succeed, you could check the address of IpBuffer, which should be located in the range of .sysmem. It should work if you state the size of heap correctly.

    Last, the mode could be chosen in the drop-down menu adjacent to the 'Build' button.

    Allen

  • Thanks Allen,

    That was exactly what i was looking for. Using MSMSC shown a 7 times increment in speed than with DDR3 with a simple code.

    Regards,

    Sohal