Performance: F("string") in a function

Nosing around for some performance tweaks I ran into the following:

2 performance related pieces of info:

  1. F("string") - stores the string in flash, and calls it from there when needed instead of storing it in ram
  2. After a function runs, the ram used for that function is released and available again for the program.

If I understand this correct;:

The following is a simplified example with missing bits.

void printString(){
lcd.print(F("Hello World"));
}

void loop(){
printString();
}

Would this be a waste of flash space ?
Or is the F() usage here still giving a performance gain ? (though as little as it may be in this example)

Looking at the given performance information, I would like to think that if I not use the F() here, the "Hello World" string would be used only when the function would get called.

Or, is the function itself already loaded into memory at start up; and would I not use the F(), it would bloat the program total ram usage because of the extra strings ?

Both the function and string are in flash.
There is no particular performance gain (possibly even a loss), but you're not wasting precious RAM with a constant string.

AWOL:
Both the function and string are in flash.
There is no particular performance gain (possibly even a loss), but you're not wasting precious RAM with a constant string.

Hi Awol,

Ah :slight_smile:

so, if the function is already in flash, the use of F() becomes useless ? and though tiny, becomes overhead ?

Of course the function is in flash - where else could it be?

No, there is a definite advantage to putting the string in flash.

AWOL:
Of course the function is in flash - where else could it be?

No, there is a definite advantage to putting the string in flash.

If the program is started on an uno for example, running.

Ofc it is on flash, but does the entire program get loaded into memory on bootup, or does it call parts from flash on the fly as the program requires it while running from ram.

The program is in flash, where it stays, because there is nowhere else for it to go, or for it to come from.

No, there is a definite advantage to putting the string in flash.

The string is in flash, too. That's where it would be copied to SRAM from.

What I think you mean is that there is a definite advantage, by using F(), in keeping the string out of SRAM.

You're quite correct - I should have written "keeping" rather than "putting".