-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
High level style of string manipulation in c language (IDFGH-10764) #11980
Comments
You can use the strings library of the C++ standard library in ESP-IDF. What particular problems do you encounter or what particular features would you like to have? |
But isn't the c++ library too heavy ? And also not sure if i can mix c with c++, i think so, but.... |
Depends on what your requirements are. Hence me asking which problems you encounter. Have you tried using it on your project? |
No. I never used c++ on esp32. Just to really learn and code faster. It's not the first time I've run into this "problem". Something like that only for int:
|
In
Note that you need to enable exceptions for this, but this all works and compiles on an ESP32. The rest of the C++ standard library should cover most of the day-to-day programming needs for strings and also has more advanced concepts for rather special cases.
You can, it's perfectly legal. You need to consider language linking and designated initializers, though. |
I think str is local variable, no ? I think i need to allocate this memory using new operator. |
You don't need to manually allocate or de-allocate memory when using |
C++ doen't have garbage collector, right ? And local variables no longer exist outside the function. If std::string allocate memory implicitly, i need to deallocate later, i just don't know if it use free or delete for this. |
No, it does not. But it has automatic destruction, which ensures that all memory is deallocated without user interaction (if the type supports it, and
Yes, but if they are returned, they are automatically transferred to calling function. Transfer can mean copying the object, moving it, or, if the compiler is able to optimize, constructing the local variable directly in the scope of the calling function. This all happens automatically for Even if you are not programming in C++, it might be a good chance to consider switching to it, if just for the parts dealing with strings. The C++ standard library has several advantages for users as well as for us:
If you cannot use |
Very good explanation. The below doubt is valid both for c and c++ : If i pass a string dynamic allocated (by pointer) to another lib, like network lib for example, to send this message by wifi. How to know the right time to release the resource ( here the dynamically allocated memory for the string ) ?
Thank's. |
If you pass a |
Yes, i know. In the case of websocket server, would you know how to inform me ? Complicated to know when release resource when dealing with network library. Thank's. |
Still assuming that you pass |
@baldhead69 If there are no other questions, could we close this issue? |
Is your feature request related to a problem?
No response
Describe the solution you'd like.
I would like to suggest a better way to manipulate strings in c, ie, better and quickly way, mainly quickly way.
Something like a high level language like java for example, with several ready and easy to use methods to manipulate strings with static or dynamic memory allocation options.
This lib must be added in https://components.espressif.com/
Possible candidate:
I never used this lib, i find his suggestion on stackoverflow.
https://bstring.sourceforge.net/
Describe alternatives you've considered.
No response
Additional context.
No response
The text was updated successfully, but these errors were encountered: