OK, so I've read all these articles about PROGMEM and why it's good for storing const strings. I get it.
I understand that #define is actually a compiler directive and it substitutes the value into the program code at compile time, thus it ends up in flash memory instead of ram.
I understand that PROGMEM tells the compiler to store the value into flash memory instead of ram. That the Arduino compiler normally puts a variable in ram even if you declare it as const. (Note: The compiler for some of my other microcontrollers knows if it's a const to put it in flash.)
I understand that PROGMEM is preferable to #define for strings, if you use the string more than once in your code, because PROGMEM will only store one copy in flash, whereas the #define compiler directive causes it to be inserted every place you use it.
I try to mostly avoid using literals as a matter of good programming practice.
But no real discussion about PROGMEM vs #define for const numbers.
How about bytes, ints and longs? How about ones that I use only once, and the ones that I use all over the place?
For ints, it seems to to me to be to be pretty much a wash. Because you either store the 16-bit value, or the 16-bit address of the value. When compiled to assembly, the microprocessor fetches the value (directly or indirectly) into its register at the same speed -- correct? (I'm basing this assumption on my knowledge of other processor families.)
So how does this affect memory usage and speed for bytes and longs?
And do I have to use pgm_read_byte(), pgm_read_int(), and pgm_read_long() to get a number stored with PROGMEM out of flash? That seems like a pain-in-the-butt to keep doing all over the place and I'm sure must really slow it down. Thus, a strong argument for #define for numeric constants. (Note: Again, compilers for my other microcontrollers don't require this.)
And why would I need to use pgm_read_whatever() to get it out of flash? With a 16-bit address the processor can address 64K of memory of whatever type. Is the 2K of ram and 32K of flash in separate address spaces?
I could design and run some benchmarks to test this, and I still might, but no doubt a few of you can just tell me and even explain why. I would certainly like to understand the "why" part, It makes me a better geek in the future!
Thanks!