// the find
antirez/sds
Simple Dynamic Strings library for C
SDS is a dynamic string library for C that stores metadata in a header just before the returned pointer, so the string itself is a valid C string you can pass to printf and standard library functions without any wrapping. It's extracted from Redis, where it's been running in production for over a decade. If you're writing C and tired of manual strlen/realloc/buffer tracking, this is the mature, battle-tested answer.
The in-prefix header design is genuinely clever — O(1) sdslen(), binary-safe storage, and direct compatibility with C string functions all fall out of the same trick. The dynamic header size in v2 (different struct sizes for small vs large strings) means short strings don't pay the overhead of 64-bit length fields. The zero-copy append pattern with sdsMakeRoomFor() + sdsIncrLen() is a real performance technique that Redis uses in its networking path, not just a demo. The allocator abstraction in sdsalloc.h lets you swap in jemalloc or a custom allocator by editing three macros.
The v1→v2 binary incompatibility is real and the README buries it in a small note at the top — if you're integrating this into something that serializes SDS headers to disk or across processes, you'll get burned. The API requires callers to reassign the pointer after every mutation (s = sdscat(s, ...)) which is error-prone and the compiler won't catch it if you forget. There's no thread safety anywhere — fine for Redis's single-threaded model, needs explicit locking if you share strings across threads. It's also essentially a single-author project that's only updated when Redis needs something; don't expect active maintenance or issue responses.