I currently have an app with a large number of settings stored in nvs. A decent amount of code is written to retrieve these settings into structures for access throughout the app as well as update settings when required (which is rarely).
I am trying to determine where I might be able to reduce code size and memory consumption. One thought is to directly access these settings in nvs whenever I use them, which would basically be continuously. Would this be an appropriate strategy?
Using nvs for dynamic variables to reduce code size
-
- Posts: 9729
- Joined: Thu Nov 26, 2015 4:08 am
Re: Using nvs for dynamic variables to reduce code size
How about having a global struct in RAM reflecting all these settings? On startup, you can retrieve everything from NVS and dump it into the struct. When a value changes, you can change it in the struct then call a routine that writes back all members that have changed. If the amount of changes is very low and you won't need forward compatibility of the settings, you may even write the entire struct to NVS as a blob.
Re: Using nvs for dynamic variables to reduce code size
That is essentially when I am doing now - reading everything from nvs and putting into global struct. What I am trying to figure out is whether or not I could potentially bypass the struct, reading variables from nvs whenever they are used.
As I said before, this would mean that I am calling nvs everytime time I access a variable which is pretty much constantly. I'm assuming that this is not as efficient from a performance perspective although no clue by how much. Just looking for some insight.
As I said before, this would mean that I am calling nvs everytime time I access a variable which is pretty much constantly. I'm assuming that this is not as efficient from a performance perspective although no clue by how much. Just looking for some insight.
Re: Using nvs for dynamic variables to reduce code size
NVS does maintain a cache which helps find specific key in flash without having to scan through all the items stored in all pages. Once the location of the key-value pair is found using the cache, NVS still needs to retrieve the actual value from flash (value is not stored in cache). Cache lookup time will depend on the number of pages in NVS partition and the number of other key-value pairs stored therein. It's pretty hard to give a single estimate. The best would be to time an nvs_get operation you have in your program (using esp_timer_get_time, for example).
Who is online
Users browsing this forum: No registered users and 108 guests