Can the String object extend its own memory? I don't think so. I had some weird problems with a sketch (garbage in variables, etc), kind of typical of a buffer overrun, and I changed my String delaration to;
It allocates new memory, puts the extended text in there, then the previous memory is freed.
Chances are high that the freed small memory is too small for new strings, because everybody using String objects, always grows them.
Thus you have a lot of unusable garbage memory and need way more than really required.
There's no protection against too little available dynamic memory in the Arduino, even if a serial monitor is attached you won't see an error message, unless you programmed such a thing yourself. Nobody using String objects checks for memory problems.
Bottom line: Strings are great, but not recommended for people who like to use String objects.
Thanks for the tips. I noticed in other posts there's not much love for String().
In the past there may have been issues with using String due to memory issues, but reportedly those issues have been fixed. For newbies the String functions are fairly easy to use and understand.
Thanks for this very clear and helpful writeup. (+)
Seems the Arduino String memory fragmentation issue is really solved.
String overhead is impressive, interesting that RAM overhead is rather small.
My compiled code goes up 2K in size when I use a String for just one object instead of a char[] array. But I am not concerned with size - yet. There does not seem to be a performance penalty, just size.
Old topic, yes, but with the Due/Zero/Teensy/Esp8266 I think it warrants an update.
It's really time to move past the "old" avr micros when we can, otherwise we will continue to program in the "dark ages".
Using the String class is a real boon for cleaner/easier to read code. For beginners in particular that is a good thing. Yes the old hands can use old str??? functions where absolutely necessary, but moving to faster 32 bit arm (and esp8266) processors with more memory make that less and less important.
Even the standard template vector lib can be used efficiently on the arms and esp8266.
So yes it's 2015, even Atmel knows it, hence the newer arm cores.
For my part, I will buy no further avr micros, they just don't make sense for anyone but the beginner that want to flash an LED.