PROGMEM vs #define vs const

When should each be used?

I am wondering if I should use #define to store some strings or PROGMEM? Which one uses the least amount of SRAM? I am looking for READ-ONLY solutions.

Example:

define WELCOME_MSG "Hello"

vs.

prog_char WELCOME_MSG[] PROGMEM = "Hello";

The #define is a pre-processor directive. The pre-processor will substitute the value on the right everywhere the value on the left occurs. This has the potential to replicate the string all over the place.

The PROGMEM solution ensures that there is one copy of the string, stored in read only memory.

With strings, use PROGMEM.

(For the reasons given by PaulS)

When doing things like only including error checking, or having set numbers that you need to change easily (like pin numbers), define would be more appropriate.

To jump in here, is it suitable to use Progmem to store arrays, such like the ones for storing characters for LCD fonts.

like the below:

char bn1[]={1,2,1, 3,1,4, 2,2,1, 2,2,1, 1,4,1, 1,2,2, 1,2,2, 2,2,1, 1,2,1, 1,2,1};
char bn2[]={1,4,1, 4,1,4, 7,6,5, 6,6,1, 5,6,1, 5,6,7, 1,6,7, 4,4,1, 1,6,1, 5,6,1};
char bn3[]={1,3,1, 3,1,3, 1,3,3, 3,3,1, 4,4,1, 3,3,1, 1,3,1, 4,4,1, 1,3,1, 3,3,1};

And can this be done from inside a library, if my arrays (like the above) are in the library itself?

I am defining a few fonts you see...

Thanks, and sorry to hijack.

To jump in here, is it suitable to use Progmem to store arrays, such like the ones for storing characters for LCD fonts.

Yes it's perfectly normal to do that. You need to ensure that you declare your data so that both the pointer to it, and the data itself end up in flash memory. Like this:

prog_uint8_t bn1[] PROGMEM={1,2,1, 3,1,4, 2,2,1, 2,2,1, 1,4,1, 1,2,2, 1,2,2, 2,2,1, 1,2,1, 1,2,1};

Now that your data is in flash you will need to use the _P avr-libc functions to extract it to a local buffer before you can use any functions that assume the data is in SRAM.