Skip to content

Progmem F() Strings Manager #4270

Closed
Closed
@Hiddenvision

Description

@Hiddenvision

Again, Not an issue but more of an Improvement thought.

I read that using Progmem for read only strings is all cool and dandy
but the compiling/linking process does not optimise repeated text used.

I was toying with a Strings manager concept that would handle all the static strings.
So you could perhaps litter your code with F_(55) where strings are required.
Save all the Indexed Strings in a txt file with a little tool to (add/search/replace/delete) entries.

F_(int i); being a simple function to return a constructed string.

An example optimizedStrings.h file

const char HTTP[] PROGMEM = "http:";
const char DOTCOM[] PROGMEM = ".com";
const char DOTCOUK[] PROGMEM = ".co.uk";
const char WEBSITE[] PROGMEM = "visitme";
const char HELPSITE[] PROGMEM = "helpme";
const char THANKS[] PROGMEM = "Thanks";
const char MR[] PROGMEM = "Mr:";
const char MRS[] PROGMEM = "Mrs:";
const char SMITH[] PROGMEM = "Smith";
const char PAGE[] PROGMEM = "Page ";
const char NOTHING[] PROGMEM = "Nothing ";
const char UNIQUE[] PROGMEM = "unique";
const char UNKNOWN[] PROGMEM = "UNKNOWN";

String F_(int i){
 switch (i) {
  case 1:     return (String) FPSTR(MR) + FPSTR(SMITH);
  case 2:     return (String) FPSTR(MRS) + FPSTR(SMITH);
  case 3:     return (String) FPSTR(HTTP) + FPSTR(WEBSITE) + FPSTR(DOTCOM);
  case 3:     return (String) FPSTR(HTTP) + FPSTR(HELPSITE) + FPSTR(DOTCOUK); 
  case 55:   return (String) FPSTR(NOTHING) + FPSTR(UNIQUE);
  case 721: return (String) FPSTR(PAGE) + FPSTR(UNIQUE) + FPSTR(THANKS); 
  default: return (String) FPSTR(UNKNOWN) + String(i); 
 }
}

end of optimizedStrings.h

As you can see from this random example trying to create and maintain this sort of thing by hand would be a nightmare but if technically this could save some space then to automate the creation of the builder function and const char progmem bits, is relatively easy to do from my point.
As a precompile process all the user strings can be studied and duplicates optimised.
Simple little exe to buz thru an indexed txt file doing the pre optimising stuff and outputting a fresh include file ready for compile.

Just wondering if this would be worth looking at or would it be a wasted folly.
I am no pro coder, I'll slap on more code than sunblock, until the resources run low,
and I'll be the first to say I can over complicate a problem that does not exist just for the fun of it.
It may even be the worst thing to even consider and produce horrendous output,
happy to take any comment.!

Now that I can do OTA > 500k, perhaps I wont even think of it again.
But wasted space is ditto.
I did this on the little Atmel devices when I was running low on space, 32k was easy to fill.!
That was not automated, but like I said, 32k is easy to fill, so I had limited text to manage.

It could be calculated that saving space takes time, so there is always a trade-off.

Hv

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions