-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Move String constants to FLASH from heap/SRAM (Esp.cpp) #5037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
IMHO all Your "WDT", "SOFT_WDT" will remain in RAM. So maybe better solution can be: |
@Pablo2048 there are many of them like this in this file, i guess more over whole framework and libs.. |
@jindrichsirucek you are correct: this is an ongoing initiative, to increase available heap, so all help in this direction is welcome. About the different ways discussed here:
@jindrichsirucek feel free to make a PR to help with this. Please include fixes for all cases that you see. I strongly suggest to test building each string that you move individually, i.e.: don't move a bunch of them and then build to check how it went. The reason for this is that not all moves will bring a benefit. Here is some info from what I remember (memory is frail, so please double check this yourself):
|
@devyte Thx a lot for explaining and sharing.. a) Which branch I should use for PR? - I have never done that before.. b) Is this the easiest way how to write that code? I mean c) I don't know how to test yet at all, in here :-D.. And also according what I found, it looks like, that all texts except "" takes HEAP - so we can optimize them all in one time, right?
|
@jindrichsirucek to make a PR:
|
About point 1, maybe I didn't explain it correctly. As I said, I don't remember all the details anymore, I'd have to experiment to refresh memory. I suggest:
As I explained above, String(F("text")).c_str() will load the string into a heap temporarily, then extract the c_str() from it, then discard it. So it is a temporary increase in heap usage. Interesting find about the LE macro, I was not aware of it. I also don't understand it :p maybe @earlephilhower will? It looks like a forced section or something. |
@Pablo2048 @jindrichsirucek FYI, I've got a PR in our newlib to redo the *printf-type calls to be always safe for PROGMEM format strings and parameters (among other memory saving things), but it's not landed yet. |
@earlephilhower pls can you provide code example of what you have explained
And can you pls let us know here when the PR will be usable part of code, so I can make changes using this new approach pls? Or is there a way how to github will notify me, that changes are incorporated? (I have subscribed to that PR you have linked).. |
Works: About the newlib changes, I think you can follow the PR. If not, just add a reply to that PR chain and you'll be notified when it's incorporated or tossed. |
@earlephilhower ok.. but when the change will be (hopefully) incorporated than both of the examples will work or only the one with capital S |
I think realistically it's a while away. Not been discussed so far for 2.5.0. It's still possible to move lots of format strings to PROGMEM by modifying the *printf to *printf_P, so if you really do want to get them to flash only, it's possible for all but the parameters. |
Its like going through the all code twice, seems like not good idea.. So i will wait with changes.. Is there a way how to push the request to discussion somehow? But thanks for showing me already working |
I have just received notification, that the PR |
gcc/toolchain environment needs recompilation with this update. |
Closing as almost all core strings are now in flash and printfs() can handle progmem format and param strings. |
Hello, I have quite big project and dealing with small heap, so I did big PROGMEM modifications of my code to release HEAP.
When I was moving string constants to flash in my program I have found s. consts. in basic arduino framework like here:
Arduino/cores/esp8266/Esp.cpp
Line 397 in 8da1d78
So I suggest to put them in FLASH to save precious RAM. I didnt figure out how to make PR; neigther I know how to correctly (best optimized way) put these strings to FLASH.
In my local code I use this:
sprintf(&buff[0], String(F("Fatal exception:%d flag:%d (%s) epc1:0x%08x epc2:0x%08x epc3:0x%08x excvaddr:0x%08x depc:0x%08x")).c_str(), resetInfo.exccause, resetInfo.reason, (resetInfo.reason == 0 ? "DEFAULT" : resetInfo.reason == 1 ? "WDT" : resetInfo.reason == 2 ? "EXCEPTION" : resetInfo.reason == 3 ? "SOFT_WDT" : resetInfo.reason == 4 ? "SOFT_RESTART" : resetInfo.reason == 5 ? "DEEP_SLEEP_AWAKE" : resetInfo.reason == 6 ? "EXT_SYS_RST" : "???"), resetInfo.epc1, resetInfo.epc2, resetInfo.epc3, resetInfo.excvaddr, resetInfo.depc);
this is the changed part:
String(F("Fatal exception:%d flag:%d (%s) epc1:0x%08x epc2:0x%08x epc3:0x%08x excvaddr:0x%08x depc:0x%08x")).c_str()
which Im not sure if is the best way - but it works and 80B of ram is saved. Is it, or is there better way how to do it? Maybe some MACRO could be used..
There are of course other const strings in this file and i suppose more anywhere else..
I have noticed @devyte you have assigned project in TODO, maybe I could help with taht if somebody will tell me how it should be done correctly and how to post code changes..
The text was updated successfully, but these errors were encountered: