A C library for heap-allocated strings that are binary safe, efficient, and compatible with standard C string functions.
SDS (Simple Dynamic Strings) is a C library that provides heap-allocated, binary-safe strings as an alternative to C's standard null-terminated strings. It solves common issues like buffer overflows and inefficient concatenation by managing memory automatically while keeping compatibility with libc functions.
C developers who need efficient, safe string manipulation for applications like networking servers, data processing, or embedded systems where performance and memory control are critical.
Developers choose SDS because it combines the safety and convenience of high-level string libraries with the performance and interoperability of low-level C, all in a minimal, single-file library that's easy to embed.
Simple Dynamic Strings library for C
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Strings can hold any binary data, including null bytes, without issues, as demonstrated with sdsnewlen() for binary-safe creation and manipulation.
Length is stored in a prefix, making sdslen() an O(1) operation, unlike libc's strlen which is O(n), improving performance for large strings.
Metadata and string data are in one memory block, enhancing cache locality and reducing fragmentation, as noted in the README for performance benefits.
SDS strings are char pointers, so they can be passed directly to standard C functions like printf() without extra calls or struct access.
Modifying functions like sdscat() return new pointers, and forgetting to reassign can lead to memory leaks or dangling references, a common pitfall emphasized in the README.
Sharing SDS strings across a program is error-prone without reference counting, increasing the risk of memory leaks or incorrect modifications, as warned in the disadvantages section.
Version 2 is not binary compatible with V1, which can break existing deployments without source code changes, requiring recompilation and potential debugging.
Lacks built-in support for Unicode, regular expressions, or advanced string manipulations, forcing developers to implement these manually for complex text processing.