String management #239
Replies: 2 comments 2 replies
-
Note that String usage does not necessary cause heap fragmentation: for small allocations, the first free blocks are reused. Heap fragmentation is caused when allocating a lot of large segments of memory. Esp-idf have some callbacks to track heap allocations and deallocations that you can use with Arduino using pioarduino hybrid compilation. if you activate and print those you will see that esp-idf and Arduino itself are doing a LOT of heap allocations and dealloc, far more than your apps probably does and also for small quantities. WiFi is especially using heap allocations a lot and frequently. heap is not an issue when used correctly and free the stack size. Increasing stack size is a hell for apps using a lot of tasks because it creates an amount of memory that is not necessarily used by the app and count against the stack size when creating tasks. |
Beta Was this translation helpful? Give feedback.
-
If I understand correctly, String on Arduino has been greatly optimized, and its performance isn't as bad as I thought. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In C++ I can think of several ways to perform operations with strings of unknown length (we don't know their size at compile time).
In this case, two possibilities occur to me:
In my opinion, there's no good choice, as each has its advantages and disadvantages, and none are 100% portable. Choosing one is a matter of taste. Therefore, I think it's up to you, as repository managers, to choose one option. I will use it for future optimizations.
NOTE: I prefer str::string, but since I only use an ESP32 and an Arduino-based platform, I'm not sure if it supports other configurations.
Beta Was this translation helpful? Give feedback.
All reactions