-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Copy ESP8266 String w/SSO to ESP32 repo #2715
Conversation
I redid the ESP8266 WString library to enable small string optimization (SSO) a while back, and think it would be helpful even on the ESP32 with its higher memory complement. SSO avoids lots of tiny mallocs() on the heap which cause fragmentation by using the memory in the class object itself to store the actual string and only mallocing() for buffers that are larger than what can fit in thie class object. Modern C++ std::string implementations have this optimization as well, but since we're using Arduino strings we had to roll our own.
3059673
to
bd483f5
Compare
Welcome to the ESP32 scene @earlephilhower :) Thanks for the update! |
@@ -35,295 +35,292 @@ class StringSumHelper; | |||
// an abstract class used as a means to proide a unique pointer type | |||
// but really has no body | |||
class __FlashStringHelper; | |||
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal))) | |||
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WString.h: 38:0: warning: "FPSTR" redefined
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
WString.h:29: In file included from
Arduino.h:152: from
[…]
pgmspace.h:35: note this is the location of the previous definition
#define FPSTR(p) ((const char *)(p))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I didn't catch that difference that needed patching, sorry. Weird how it got through CI, though.
Did you want to change the #define
s back in your own PR, @dok-net, or would you like me to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #2726 undoes the redefinition, returning it to the ESP32 native definition. Since you have a failing case, can you check that it looks good for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more warnings with PR #2726 in place, thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged :)
FYI: #2961 re-implements this fix by keeping the definition from ESP8266, but removing the duplicate (but incorrect) definition of What is different now is the PSTR() macro, defined in <pgmspace.h>. This macro is a no-op in ESP32, but uses PROGMEM in ESP8266. |
I redid the ESP8266 WString library to enable small string optimization
(SSO) a while back, and think it would be helpful even on the ESP32 with
its higher memory complement.
SSO avoids lots of tiny mallocs() on the heap which cause fragmentation
by using the memory in the class object itself to store the actual
string and only mallocing() for buffers that are larger than what can
fit in thie class object. Modern C++ std::string implementations have
this optimization as well, but since we're using Arduino strings we had
to roll our own.