Hi all
For a new project I am using a mcu (stm32f031) with a small amount of ram (4 KB).
Used to mcu with> = 32KB of ram, in my projects I create many local variables that are destroyed after the macro is terminated.To make the same macros work I had to transform local variables into global variables.
Are there some compiler settings to allow you to optimize the use of the ram, perhaps at the expense of general performance?
Tips and tricks for saving RAM
-
- Posts: 89
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 10:06 am
- Location: Italy
- Has thanked: 37 times
- Been thanked: 10 times
-
- Valued Contributor
- Posts: 1628
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
Re: Tips and tricks for saving RAM
Hi Oscar,
The compiler settings just control the size of the code - the RAM use depends on the number of variables and also depth of procedure calls.
So the things you can do - use the smallest possible variable size for data types.
Use loops with your own variable as the index. Flowcode will generate a variable for any for loop (whereas you can reuse 'i'),
Be careful with recursion.
Limit the size of arrays and strings...
Minimize the number of arguments to macros (which also go on the stack) - arrays and strings also pass a size.
Personally, I'd still use locals - i in one macro effectively uses the same memory as i in another and reduces the risk of 'side effects' and hard to find bugs..
Can you offload any data to (i2c /spi) eeprom or sd card etc..
Martin
The compiler settings just control the size of the code - the RAM use depends on the number of variables and also depth of procedure calls.
So the things you can do - use the smallest possible variable size for data types.
Use loops with your own variable as the index. Flowcode will generate a variable for any for loop (whereas you can reuse 'i'),
Be careful with recursion.
Limit the size of arrays and strings...
Minimize the number of arguments to macros (which also go on the stack) - arrays and strings also pass a size.
Personally, I'd still use locals - i in one macro effectively uses the same memory as i in another and reduces the risk of 'side effects' and hard to find bugs..
Can you offload any data to (i2c /spi) eeprom or sd card etc..
Martin