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.

How to use malloc() function using the assigned Heap Size memory on DSK6416?

Hi All,

I am currently trying to create an array (called arrI) of 20,000 integers using the malloc() function, andI am doing the following condition: 

If (arrI == NULL)

        printf(“Not enough memory\n”);

To check that the memory has been allocated. Unfortunately I am receiving the message -> Not enough memory. Which in C means that the memory has not been allocated. 

I tried setting the heap size but still kept getting the not enough memory error. Could you kindly guide on how to set the heap size in order to allow memory allocation for this size of array? I need to allocate memory dynamically for variables at run time. 

Regards,

Josef

  • Hi Josef,

         From a C reference below:

        "To allocate memory on the heap, you must use malloc() or calloc(), which are built-in C functions. Once you have allocated memory on the heap, you are responsible for using free() to deallocate that memory once you don't need it any more. If you fail to do this, your program will have what is known as a memory leak. That is, memory on the heap will still be set aside (and won't be available to other processes)"

    -kel