Boo0ns / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Rethink the String class. #451

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The current String class obscures the dynamic memory allocation that's 
happening behind the scenes (particularly in the constructor and the += 
operator).  This makes it harder to realize that you have to worry about 
running out of memory and harder to check if you have.  We need to rethink the 
API of the String class to make the memory management more explicit (without, I 
hope, making it much more complex).

One question is whether to keep the name String or switch to something like 
Buffer.  Another is whether the memory should be allocated on the stack or the 
heap.  Either way, I think we need to remove the constructors that provide an 
initial value (replacing them with ones that allow you to specify the buffer 
size) and remove the + and += operators (replacing them with append() functions 
or write() / print() / println()).  

Java's StringBuilder is a useful reference.

Original issue reported on code.google.com by dmel...@gmail.com on 7 Jan 2011 at 2:20

GoogleCodeExporter commented 9 years ago
Basically, we're keeping the String class using dynamically-allocated buffers, 
but changing the API slightly to allow for robust error handling.

Original comment by dmel...@gmail.com on 26 Mar 2011 at 5:50