lasselukkari / aWOT

Arduino web server library.
MIT License
283 stars 41 forks source link

Use built in P macro instead of F for strings #119

Closed lasselukkari closed 3 years ago

lasselukkari commented 3 years ago

HelloWorld example with current master compiled on Arduino Uno: Sketch uses 21104 bytes (65%) of program storage space. Maximum is 32256 bytes. Global variables use 860 bytes (41%) of dynamic memory, leaving 1188 bytes for local variables. Maximum is 2048 bytes.

After changes: Sketch uses 20268 bytes (62%) of program storage space. Maximum is 32256 bytes. Global variables use 860 bytes (41%) of dynamic memory, leaving 1188 bytes for local variables. Maximum is 2048 bytes.

EmperorArthur commented 3 years ago

That's really interesting. Given that __FlashStringHelper and the F macro seemed to just be a typedef of an inline version of the P macro if "AVR" is not defince. I wonder what was causing the increased memory use. 836 bytes is not a small amount!

Worth checking the memory difference between:

Serial.print(F("test"));

and

#define P(name) static const unsigned char name[] PROGMEM
P(test) = "test";
Serial.print(reinterpret_cast<const __FlashStringHelper *>(test));

along with

#define P(name) static const unsigned char name[] __attribute__(( section(".progmem." #name) ))
P(test) = "test";
Serial.print(reinterpret_cast<const __FlashStringHelper *>(test));

If I remember correctly, all three of these should behave exactly the same. So, why don't they?