I found this comment on Serial.print:
You can pass flash-memory based strings to Serial.print() by wrapping them with F(). For example :
What does it mean to pass flash-memory based strings?
It means the string isn't using up RAM.
When you compile your program it says how much program memory (stored in flash) you are using and how much dynamic ram you are using.
If you use F() you can move constant strings to the program memory instead of the ram. This will take up space that will decrease the amount of other code you can write. But it will free up dynamic ram.
My chip has 32KB of Flash memory (2Kb taken up by bootloader) and 2KB or RAM. Sometimes I need to store lots of data in RAM so I move the constant strings to Flash memory. Sometimes my program has a lot of steps and I have a shortage of Flash memory so I leave the strings in RAM.
Oct 06, 2016, 07:52 pm Last Edit: Oct 06, 2016, 07:55 pm by mrburnette
If you use F() you can move constant strings to the program memory instead of the ram.
Actually what happens in a Harvard architecture uC is that the compiled string stays in flash and does not get copied to SRAM during the C++ initialization that happens before your sketch receives run control.
Since the string is not moved to SRAM, it has the PROGMEM property and runs from flash.
Sometimes my program has a lot of steps and I have a shortage of Flash memory so I leave the strings in RAM.
That's not how it works.
Your string constants are ALWAYS in flash memory. They have to be, because when you take power away from RAM everything's gone. When you put power back on again, they have to be reloaded from somewhere, and that somewhere is the flash memory. Leaving off PROGMEM will do nothing to save you significant amounts of flash memory.
It's just that a normal part of initializing a C++ program is to load those arrays into SRAM before setup(). PROGMEM is an AVR-specific attribute that can be applied to variables that tells the compiler to not do that. Because flash is in a different memory space than RAM, special functions are needed to access from flash than from RAM.