3 ms·
There is also Better String Library, similar self-contained library with C-style string compatibility: http://bstring.sourceforge.net/ http://bstring.sourcefor
by paulsmith 7y ago
There is also Better String Library, similar self-contained library with C-style string compatibility:
http://bstring.sourceforge.net/ http://bstring.sourceforge.net/
- aidenn0 7y agoTFA specifically names what is different between SDS and libraries like bstring: > Normally dynamic string libraries for C are implemented using a structure that defines the string. The structure has a pointer field that is managed by the string function, so it looks like this: struct yourAverageStringLibrary { char *buf; size_t len; ... possibly more fields here ... }; > SDS strings as already mentioned don't follow this schema, and are instead a single allocation with a prefix that lives before the address actually returned for the string.
- dho85 7y agoWhat the page doesn't really acknowledge is that its "single allocation with a prefix" design is significantly more dangerous than the "separate struct" design. Particularly in that it's incompatible with the address sanitizer.