Freezing Dictonary in Flash
Posted: Thu May 31, 2018 7:48 am
Hi,
I understand that freezing strings in the flash saves RAM in micropython.
A source file containing
which is frozen into the falsh and then imported saves RAM.
Is is also possible to freeze a dictonary into the flash and import it, to reduce the RAM usage? Something like this:
And then import the dictonary?
Or do I have to define each string in the dictonary as a constant and build the dictonary like this:
The point is, that I want to not have the strings in RAM but in the flash, to reduce unnecessary RAM usage. Freezing the whole dictonary at once into the flash would make the source code more readable.
I understand that freezing strings in the flash saves RAM in micropython.
A source file containing
Code: Select all
MY_STRING = 'this is a long string, but I want it to be only a machine word in the RAM of the actual devcie'
Is is also possible to freeze a dictonary into the flash and import it, to reduce the RAM usage? Something like this:
Code: Select all
MY_DICTONARY = {1: 'hello', 2: 'world', 3: 'this is a long string, but I want it to be only a machine word in the RAM of the actual devcie'}
Or do I have to define each string in the dictonary as a constant and build the dictonary like this:
Code: Select all
MY_STRING_1 = 'hello'
MY_STRING_2= 'wolrd'
MY_STRING_3 = 'this is a long string, but I want it to be only a machine word in the RAM of the actual devcie'
Code: Select all
import my_strings_in_flash
my_dict = {1: my_strings_in_flash.MY_STRING_1, 2 : my_strings_in_flash.MY_STRING_2, 3: my_strings_in_flash.MY_STRING_3}