Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation app: reduce memory usage #362

Merged
merged 2 commits into from
Jun 1, 2021
Merged

Conversation

JF002
Copy link
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)!
@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