Allocating Heap Memory
Heap
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® 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

1

Step 1: Open the "Project Properties" Window

From MPLAB X with the Project Open:

  • When the Project Properties window opens up locate the categories section of the window
categories.png
Click image to enlarge.

2

Step 2: 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
project_properties.png
Click image to enlarge.

3

Step 3: 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
heapsize.png
Click image to enlarge.

20th Annual
Microchip MASTERs Conference 2016
Register now - Deadline: July 29

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.