Is it correct to say that when a copy of the String object is made, another copy of the string is allocated? Instead can it use a smart pointer to increment the reference to the char* pointer? In many instances I have a readonly String object on the stack and I want to store it in a global variable for later use, I don’t want to make a copy of the char array, only a copy the String object. How do I achieve that currently?
I thought String is part of the Arduino project and the question is about the internal implementation, I wanted Arduino developers to respond, so maybe move it back please?
So I don't see any smart pointers. That's why I wanted to ask what the Arduino developers think about making strings immutable. @UKHeliBob did you think my question is about how to program using String class? It's not.
Text strings can be represented in two ways. you can use the String data type, which is part of the core as of version 0019, or you can make a string out of an array of type char and null-terminate it. This page described the latter method. For more details on the String object, which gives you more functionality at the cost of more memory, see the String object page.
That library is really written just like the String class with a c-string backend but without the possibility of dynamically increasing the buffer size dynamically.