3 ms·
TFA specifically names what is different between SDS and libraries like bstring: > Normally dynamic string libraries for C are implemented using a structure th
by aidenn0 7y ago
TFA 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.