Redis相关

Redis 简单动态字符(SDS)

2019-12-07  本文已影响0人  Oliver_Li

简单动态字符串SDS

SDS的定义
// V3.2之前
struct sds {
 // 记录 buf 数组中未使用字节的数量
 int free;
 // 记录 buf 数组中已使用字节的数量
 int len;
 // 字节数组,用于保存字符串
 char buf[];
};

// V3.2之后,sdshdr16/sdshdr32同理
struct __attribute__ ((__packed__)) sdshdr5 {
    unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
    char buf[];
};
struct __attribute__ ((__packed__)) sdshdr8 {
    uint8_t len; /* 已使用 */
    uint8_t alloc; /* 总长 */
    unsigned char flags; /* 3 lsb of type, 5 unused bits */
    char buf[];
};
SDS与C字符串的区别
SDS拼接时扩容策略
上一篇下一篇

猜你喜欢

热点阅读