PIC32 port data memory usage

wne1 wrote on Wednesday, October 14, 2009:

I want to find out why it us 32084/32768, which occupied about 98% data memory. Can anyone help on:
1. what part program or variables contribute such big percentage occupation.
2. How can I reduce the percentage usage, such that I can develop more my application based on this port. Thanks.

wne1 wrote on Wednesday, October 14, 2009:

I can reduce the data memory size by setting:

    #define configTOTAL_HEAP_SIZE ( ( size_t ) 0 )

But, I also compiled the port Microchip integrated their library into. The define above does not work. The resulting data memory usage is:

    kseg1 Data-Memory Usage
    section                    address  length       (dec)  Description
    -----                 -------  -----------------  -------
    .data                   0xa0000200          0xc24        3108  Initialized data
    .sdata                  0xa0000e24            0x8           8  Small initialized data
    .sbss                   0xa0000e2c           0x58          88  Small uninitialized data
    .bss                    0xa0000e84          0x844        2116  Uninitialized data
    .heap                   0xa00016c8         0x5dc0       24000  Dynamic Memory heap
    .stack                  0xa0007488          0x400        1024  Minimum space reserved for stack
             Total kseg1_data_mem used  :      0x7688       30344  92.6% of 0x8000
                Total Data Memory used  :      0x7688       30344  92.6% of 0x8000

edwards3 wrote on Wednesday, October 14, 2009:

See this page http://www.freertos.org/a00111.html

richard_damon wrote on Wednesday, October 14, 2009:

You biggest memory usage is the "malloc heap" which is set at 24k. This can probably be reduced. It’s size is set up in the option pages under the linker I believe. If your program is using the C heap, then it might make sense to use it for freeRTOS too by using heap3.c If you don’t need the heap (you don’t use malloc, even indirectly through other library calls) then you can get rid of the heap entirely. If you do use the heap, you will need to make sure that all allocations and deallocations are protected with a critical section or mutex, as I suspect the library is not set up to be naturally thread safe. (That or all allocations must be from a single thread).

wne1 wrote on Thursday, October 15, 2009:

I am still confused about where "malloc heap" is and how to reduce it. Where is the "option pages under the linker"? There is no linker file in the project tree listed in Maplab. The file "heap_3.c" is indeed included in the source files in Mplab. I don’t need the heap, but I don’t know how to get rid of the heap. Please instruct me a little more detail. Thanks.

wne1 wrote on Thursday, October 15, 2009:

I found where the 24k was set. It is in build optioin->MPLAB PIC32 linker, heap size.

richard_damon wrote on Thursday, October 15, 2009:

I don’t have the PIC32 package on my machine, but for the dsPIC/PIC24 package, in the project options, under the linker tab, is a box to set the heap size.