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.

Compiler/MSP430F6636: Calloc issue

Part Number: MSP430F6636


Tool/software: TI C/C++ Compiler

Hi,

I have problem with calloc function :

     ptr =  (int *) calloc(200, sizeof(int));
        for(i=0; i<200; i++) {
            ptr[i] = i+1;
        }

When i compile the code and debug the first line i have ptr address 0x00000000 {-12238}. Then of course code get crashed and jump to : __TI_ISR_TRAP
The point is if I change size to 50 is working fine.

I have 65% of 16KB RAM free and I want to allocated about 2KB array.


Any idea?


Regards
Kris

  • KrisL said:
    When i compile the code and debug the first line i have ptr address 0x00000000 {-12238}.

    calloc() returns a null pointer (zero) there there is insufficient free heap space for the allocation.

    The heap size is set in the project properties under Build -> MSP430 Linker -> Basic Options -> Heap size for C/C++ dynamic memory allocation (--heap_size, -heap):

    To allocate a 2KB array you need to increase the heap size to > 2KB (there is some overhead to manage the allocations).

  • This is great!! Thank you :) It was so simple :P