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.

Problem with calloc and malloc.



Hello,

I am using CCSv2.1 and trying to compute FFT, I am using DSK5416 target and I have compiled and built the code successfully but the code is not working properly with calloc and malloc functions.It is not allocating memory required , I tried changing in .cdb configuration file the stack and heap size , I also entered heap size  in build options/linker / heap size 0x0400 . I used arrays for allocating memory instead of calloc and malloc and code works fine for smal data.But my computation requires more data in next steps of code so i have to use calloc and malloc, i am not able to figure out where the problem lies and what changes i should make . This is the piece of code when executed gives "unable to allocate complex array" .

static                complex *a, *b;

if (flag == 0) {
   a = (complex *) malloc((nfft+1)*sizeof(complex));
   b = (complex *) malloc((nfft+1)*sizeof(complex));
   if ((a == NULL) || (b == NULL)) {
     printf("unable to allocate complex array \n");
     _exit(-1);
   }

Regards,

Nikita.

  •  Nikita,

    nikita kkulkarni said:

    I am using CCSv2.1 and trying to compute FFT, I am using DSK5416 target and I have compiled and built the code successfully but the code is not working properly with calloc and malloc functions.It is not allocating memory required , I tried changing in .cdb configuration file the stack and heap size , I also entered heap size  in build options/linker / heap size 0x0400 .

    I would change the heap settings only in the .CDB configuration file to avoid any conflicts between the options.

    The exact amount of heap necessary is highly dependent on the value of the variable nfft, but at first glance the 0x400 size for the heap seems small for the job, since printf() alone uses somewhat around 0x300 for its own processing (which is pre-allocated at the code initialization).

    nikita kkulkarni said:

    I used arrays for allocating memory instead of calloc and malloc and code works fine for smal data. But my computation requires more data in next steps of code so i have to use calloc and malloc, i am not able to figure out where the problem lies and what changes i should make . This is the piece of code when executed gives "unable to allocate complex array" .

    Keep in mind the C5416 memory is non-continuous between the different data pages, therefore keep this in mind when allocating your data if it is larger than 32kW - the heap used in malloc uses the memory section .sysmem that can be in a single memory segment. Since it seems you are using DSP/BIOS to configure your memory settings, you can always allocate different arrays in different memory segments, thus giving extra flexibility - check chapter 5 of DSP/BIOS User's Guide (SPRU423F).

    Hope this helps,

    Rafael