Navigation app: reduce memory usage #362
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR slightly changes how
iconMap
is declared to reduce significantly the FLASH and RAM memory consumed by this app.Before this change,
iconMap
was declare as a non-const member variable of Navigation. It means that this array was stored in FLASH. When Navigation was instantiated, the content of the flash was copied into RAM.Also,
iconMap
was declared asstd::array<std::pair<std::string, const char*>, 89>
. Each item of the array was 28B long (24B for the string, 4B for the ptr to char). Usingconst char*
instead ofstd::string
frees 20B per element in the array.Now, the array is declared as
static constexpr std::array<std::pair<const char*, const char*>, 86>
: 8B per element and it only lives in.rodata
which is in FLASH. No need to copy it into RAM.In the end, 5300B of flash were freed, and probably that much in the heap (RAM):
424644 960 47676 473280 738c0 pinetime-app-1.0.0.out
419344 960 47676 467980 7240c pinetime-app-1.0.0.out