Skip to content
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

Merged
merged 1 commit into from
Apr 26, 2019

Conversation

earlephilhower
Copy link
Contributor

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.

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.
@me-no-dev
Copy link
Member

Welcome to the ESP32 scene @earlephilhower :) Thanks for the update!

@me-no-dev me-no-dev merged commit ab309e4 into espressif:master Apr 26, 2019
@@ -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))
Copy link
Contributor

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))

Copy link
Contributor Author

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 #defines back in your own PR, @dok-net, or would you like me to do it?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged :)

@bxparks
Copy link
Contributor

bxparks commented Jul 17, 2019

FYI: #2961 re-implements this fix by keeping the definition from ESP8266, but removing the duplicate (but incorrect) definition of FPSTR() in ESP32's pgmspace.h. Therefore, the FPSTR() macro is now identical between ESP8266 and ESP32, and future merges from ESP8266 should not cause trouble.

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.

@earlephilhower earlephilhower deleted the unified-string branch December 31, 2019 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants