Optimizing static and stack memory

Previously, we explained tool-assisted techniques for optimizing heap memory, and now we will describe some tips for optimizing static and stack memory:


In embedded systems, it is particularly important to optimize the size of a binary, not only because it takes RAM memory, but also because it uses expensive flash memory. Below are some tips you can use to optimize the size of an executable:



In some cases, it is worth the effort to optimize the stack, particularly when the application has some frequent picks of stack activity (meaning that a huge stack segment would be constantly mapped to physical memory). You can watch the Memory Information view for stack allocation and inspect code that uses the stack heavily. This usually occurs in two cases: recursive calls (which should be avoided in embedded systems), and heavy usage of local variables (keeping arrays on the stack).

Note: Tasks such as finding unused objects, structures that are not optimal, and code clones, are not automated in the QNX Momentics IDE. You can search for static analysis tools with given keywords to find an appropriate tool for this task.
Related concepts
Process memory
Performance of heap allocations
Analyzing allocation patterns
Optimizing heap memory
Types of allocation overhead
Estimating the average allocation size
Tuning the allocator