Allocating For Fixed Pool and Variable Heap - mchpgfx/legato.docs GitHub Wiki
Allocating for the Fixed Pool and Variable Heap
Allocating for the Fixed Pool and Variable Heap
The MGS Harmony Library owns and manages its own memory pool. The memory pool is split into the Fixed Pools and Variable Heap.
Note: This memory management system is used by the MGS Harmony Library only. It is not related to the general allocator and all of its memory is statically allocated. The general heap is still managed from within the MHC or in the MPLABX project.
The Fixed Pool heap offers fast, fragment-free dynamic allocation. One of its drawbacks is that it can sometimes lack efficiency and can consume more memory than is necessary for a given allocation. The total size of the Fixed Pool is shown in the Memory section of the Project Settings window of Legato Composer. The defaults shown were derived based on testing of various Legato demo graphics applications.
The Variable Heap is single, often larger, memory pool. The benefit of the variable heap is that it can allocate chunks of any size. However, it can become fragmented with use.
The Variable Heap can be configured to allocate using a Best Fit or First Fit mode. The best fit mode may take longer to allocate a new chunk but works to utilize the heap as efficiently as possible, reducing fragmentation. First fit takes the opposite approach and allocates the first available block it finds, perhaps resulting in a block split.
Legato uses the fixed pool for smaller allocations in order to reduce overall memory fragmentation and reserves the variable heap for larger allocations.
Both can be configured under Project Settings->Memory.
These settings are generated into legato_config.h and are used in legato_memory.c.
By default, for performance, the memory in both the Fixed Pool and Variable Heap are not zero-ed. Widget using dirty recycled memory can sometimes lead to unexpected behavior after screen transitions. Setting Zero-sized allocation can be an option to address this.
The Debug allocator setting is available as an option to debug the graphics memory allocation. When enabled, memory allocation information is added to the generated code, which can then be routed to external console.
If you are new to MPLAB® Harmony, you should probably start with these tutorials:
- MPLAB® Harmony v3 software framework
- MPLAB® Harmony v3 Configurator Overview
- Create a New MPLAB® Harmony v3 Project
Is this page helpful? Send feedback.