Hasty Briefsbeta

Antirez/sds: Simple Dynamic Strings library for C

16 days ago
  • #memory management
  • #C programming
  • #string manipulation
  • SDS version 2 is an updated version aiming to unify Redis, Disque, Hiredis, and standalone SDS versions.
  • Not binary compatible with SDS version 1 but maintains 99% API compatibility.
  • Uses dynamic header sizes, reducing memory usage compared to V1 but may be slower for certain workloads.
  • Includes additional API functions like sdscatfmt for faster string concatenation without libc printf overhead.
  • SDS is a C string library designed to augment libc string handling with heap-allocated strings that are simpler, binary safe, and computationally efficient.
  • Uses a binary prefix before the string pointer for metadata, ensuring compatibility with C string functions.
  • Provides both high-level and low-level functions for easy manipulation and high-performance operations.
  • SDS strings are single allocations with a prefix, offering advantages like better cache locality and direct char access.
  • Disadvantages include the need to reassign returned values and potential issues with shared strings.
  • Includes functions for creating, duplicating, and managing SDS strings, as well as concatenation, formatting, and trimming.
  • Supports tokenization and joining strings, useful for command-line interfaces and networking protocols.
  • Memory management includes preallocation strategies and functions to remove free space or query allocation size.
  • Low-level API allows manual string manipulation, with functions to update length and manage shared strings via reference counting.
  • Compatible with memory checkers like Valgrind and includes allocator API for custom memory management.
  • Released under the BSD two-clause license, with contributions from Oran Agra for dynamic sized headers in version 2.