I'm dealing with HTTP Get as a client in an ESP32 so I have to deal with long strings.
There's a great debate on why people should be using the native Arduino String library, mainly due to memory fragmentation. So long-time developers friends of mine told me that it's good practice to use Glib/Gstrings that as far as I see it manage strings as structs that can add more text.
So I wanna know,
Is there a way to use or install glib as a normal library in Arduino? If it isn't implemented already
Is it gonna have any conflicts with Arduinos Strings or another native library?
it started with a discussion from this Git's list of banned C functions. So then came up that GString was the best option to go. I don't really know the differences between Gstrings, Cstrings, and Arduino String. I have used C strings before.
you can use what you want, I'm not aware of GString to be ported but that might be due to my lack of interest there. I'm good with using cStrings or strings, what matters is understanding the tradeoffs you make by picking a solution over another one and ensuring you don't overflow buffers if you handle them yourself and meet your hardware requirements (ie don't try to allocate more memory than available)
@drmpf will have some extra ideas for you I'm sure
Look you are using an ESP32, even on the smallest of the ESP's (the -01) it is fine to use the String class as long as you make sure that you don't fragment the memory. There is a lot of it, but fragmentation will ... eventually eat it. So: for dealing with a the http get (and the response etc) you have to make sure that you don't fragment the memory. That means that there are a few rules. Global Strings need to have a reserved space that they may not exceed. You can do this with the .reserve() function. You could also use c-strings for any global strings, but reserve() does the trick. (it can be confusing to work with 2 systems at the same time)
While you create a String, try not to add to other Strings, this is wasteful. And primarily make sure you Strings go out of scope, and that should clear the whole heap. It is not hugely difficult to do this, it just takes awareness while programming. One big string at a time is not a problem !
My tutorial on Taming Arduino Strings has guidelines for avoiding String fragmentation which covers in more details the suggestions of @Deva_Rishi above.
But for the ESP32, since it uses Strings under the hood, the tutorial also has a section on setting up an auto-reboot at regular intervals to clean up the ESP32.