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

Use of String in libraries #5886

Closed
PurpleAir opened this issue Mar 16, 2019 · 3 comments
Closed

Use of String in libraries #5886

PurpleAir opened this issue Mar 16, 2019 · 3 comments

Comments

@PurpleAir
Copy link
Contributor

As someone who has made great headway to remove all instances of String objects from my code, I was wondering why some libraries use them a lot, for instance the HTTPClient and WebServer libraries. If String use is not recommended, why do they still use them so much?

Are there any plans to update libraries to remove String use in the future?

@d-a-v
Copy link
Collaborator

d-a-v commented Mar 16, 2019

why do they still use them so much?

Because this is history. Anyone is welcome to improve them. There is an ongoing work for WebServer #5636, but if you have any plan to improve current code, you are welcome.

Strings are not forbidden. They make holes (heap fragmentation) so special care has to be taken with them. Use .reserve() when possible, or char* when wise. A nice improvement recently happened #5690.

@devyte
Copy link
Collaborator

devyte commented Mar 16, 2019

String use is not recommended

That sentence is incomplete. The missing part says "by inexperienced programmers".
String manages its own dynamic allocs internally, and the use must be aware of how it behaves in a tiny system like the ESP. Usage such as pass-by-value or long sequences of concats are bad. Using when receiving chars and not knowing when the sequence ends is preferable to C-style manual handling of the dynamic allocs, so it's good.
As a user, it can ease a whole lot of use cases, but you must be a responsible adult and use them correctly.
Closing due to non-issue.

@devyte devyte closed this as completed Mar 16, 2019
@PurpleAir
Copy link
Contributor Author

Thank you for the feedback.

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

No branches or pull requests

3 participants