Forum: System Workbench for STM32

Compiler Optimizations and RAM Use

I have run out of memory as evidenced by malloc returning NULL. I am looking at what variables and code I can eliminate. I am also looking at the optimizations selections at:
Project => Properties => C/C++ Build => Settings => Tool Settings tab => MCU GCC Compiler => Optimizations

I know these optimizations will affect code size in the flash. Will they also have an effect on the amount of RAM that is used?

There are two check boxes here. The are labeled:
Place the function in their own section (-ffunction-sections)
Place the data in their own section (-fdata-sections)
What effect would each of these have on RAM use?

Tunisia

Hello Stephen,

Generally when you are out of memory, you really need to use another MCU with larger RAM.

But before doing that, you need to check if you are doing the “free” when the allocated memory is no more needed in your program, you also need to optimize the size of data’s (types/structures) : (eg. no need to use 32bits integer when your variable won’t exceed 0xFF)

Concerning -ffunction-sections & -fdata-sections : these options will not affect RAM usage, but they will affect ROM usage negatively. Your executable will be begger and slower !