Re:Show HN: Stricks – managed C strings library
by kazinator on Thursday March 25, 2021 @02:23PM
(#26583610)
Here is mine, from 1999. The null-terminated data starts after the header.
In the implementation, this is used for getting at the string data:
For some reason I didn't bother with the flexible array member trick.
[ Parent
| on HN ]
Re:Show HN: Stricks – managed C strings library
by alcover on Thursday March 25, 2021 @03:07PM
(#26584113)
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.
Re:Show HN: Stricks – managed C strings library
by kazinator on Thursday March 25, 2021 @06:55PM
(#26586679)
Capacity 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.