[redis]SDS和链表
一、SDS 1、SDS结构体 redis3.2之前 :不管buf的字节数有多少,都用 4字节的len来储存长度 ,对于只存短字符串那么优点 浪费空间 ,比如只存 name ,则 len=4 则只需要一个字节8位即可表示 struct sdshdr { unsigned int len; // buf中已占字节数 unsigned int free; // buf中剩余字节数 char buf[]; // 数据空间 }; redis3.2之后: struct __attribute__ ((__packed__)) sdshdr8 { uint8_t len; //已分配字节数 uint8_t alloc; //剩余字节数 unsigned char flags; //标识属于那种类型的SDS 低3存类型,高5不使用 char buf[]; }; //........16、32、64 _ attribute _ ((_ packed _)) 关键字是为了取消字节对齐 struct test1 { char c; int i; }; struct __attribute__ ((__packed__)) test2 { char c; int i; }; int main() { cout << "size of test1:" << sizeof(struct test1) <<