Skip to content

Navigation app: reduce memory usage#362

Merged
JF002 merged 2 commits intodevelopfrom
reduce-navigation-memory-usage
Jun 1, 2021
Merged

Navigation app: reduce memory usage#362
JF002 merged 2 commits intodevelopfrom
reduce-navigation-memory-usage

Conversation

@JF002
Copy link
Copy Markdown
Collaborator

@JF002 JF002 commented May 17, 2021

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 as std::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). Using const char* instead of std::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):

  • Before : 424644 960 47676 473280 738c0 pinetime-app-1.0.0.out
  • After : 419344 960 47676 467980 7240c pinetime-app-1.0.0.out

 - Renaming and reformatting according to coding conventions
 - declare iconMap as constexpr and use char* instead of std::string

This reduces the flash usage from 424644B to 419344B (-5300B)!
Comment thread src/displayapp/screens/Navigation.cpp Outdated
@JF002 JF002 merged commit 287399f into develop Jun 1, 2021
@JF002 JF002 added this to the Version 1.2 milestone Jun 1, 2021
@Avamander Avamander deleted the reduce-navigation-memory-usage branch September 27, 2022 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants