Allocating Heap Memory in MPLAB® X IDE

Last modified by Microchip on 2024/06/24 06:34

A contiguous block of memory can be set aside to be used as a "scratch pad" by the application program at run-time. Many applications and functions require the use of a heap. When a heap is required the developer must configure the heap inside the MPLAB® IDE X project.​

Care should be taken when creating a heap. Memory used in the heap is unavailable for global variables or the stack. Making a heap larger than it needs to be may make it difficult for the linker to complete the memory allocation.

Setting up the heap

Open the "Project Properties" Window

From MPLAB X IDE with the Project Open:

  • When the Project Properties window opens up locate the categories section of the window
Categories pane in project properties window
Click image to enlarge.

Select the Linker

  • The categories section of the Project Properties lists all the configurations for the project.
  • Select the linker under the configuration you wish to build
    • xc32-ld is the linker for MPLAB XC32
    • xc16-ld is the linker for MPLAB XC16
Select linker in categories pane
Click image to enlarge.

Enter the Heap size

With the appropriate linker selected:

  • Ensure the Option Categories is set to General
  • Type the number of bytes for the heap in the line marked Heap size
  • Select OK
Enter heap size in linker window
Click image to enlarge.

Back to Top