3 ms·
Why wouldn't you store capacity ? In your API the user has to put in a var and pass it around, like in bare C.
by alcover 6y ago
Why wouldn't you store capacity ? In your API the user has to put in a var and pass it around, like in bare C.
- kazinator 6y agoCapacity is required only if you plan to grow a string in place (so you know how much you can add before reallocating). Reallocating is possible here because the string is one object, including the header. Reallocating would change the identity of the object, which is a non-starter when multiple places in the program are sharing the pointer via reference counting. Therefore, all the strings are immutable here, and so all operations return a new string object.