Programming tip: Use Flash memory

To save RAM (limited commodity), store (especially large) text strings in flash memory by using the F macro. More details here

e.g. sp.println(F("This is a very long text string that will be stored in Flash memory"));

Or, (to store in variable for later use);

const char string0[] PROGMEM = “Another long text stored in Flash Memory”;

sp.println(string0);

@kenj do I understand this correctly? If I am using really long strings in my code, i.e. having some long debug messages over serial, it would be best to store my strings with the program/flash memory rather than have it on the stack (RAM), where it could in fact cause some stack overflow issues that won’t help in my debugging process at all. Is that right? If so, great tip.

The focus of the tip was on avoiding chewing up the (limited) 1K dynamic memory by putting the format strings (typically the largest part of debug statements) into Flash memory. However, you’re right, moving the variable string off the stack does avoid some overflow issues as well.