54 Star 542 Fork 210

balloonwj / CppGuide

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
14item结构.md 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
zhangyuanlong 提交于 2020-10-08 15:33 . add articles

Memcached源码阅读十四 item结构

itemMemcached中抽象实际数据的结构,我们分析下item的一些特性,便于后续Memcached的其他特性分析。

typedef struct _stritem {
    struct _stritem *next;//item在slab中存储时,是以双链表的形式存储的,next即后向指针
    struct _stritem *prev;//prev为前向指针
    struct _stritem *h_next;//Hash桶中元素的链接指针
    rel_time_t      time;//最近访问时间
    rel_time_t      exptime;//过期时间
    int             nbytes;//数据大小
    unsigned short  refcount;//引用次数
    uint8_t         nsuffix;//不清楚什么意思?
    uint8_t         it_flags;//不清楚什么意思?
    uint8_t         slabs_clsid;//标记item属于哪个slabclass下
    uint8_t         nkey;//key的长度
    union {
          uint64_t cas;
          char end;
    } data[];//真实的数据信息
} item;

其结构图如下所示:

Item由两部分组成,item的属性信息和item的数据部分,属性信息解释如上,数据部分包括caskey和真实的value信息,item在内存中的存储形式如下:

这个图画出了部分结构,还有Hash表的结构没有画出。

这里大概介绍了item的一些信息,后面我们会分析item插入Hash表等信息。

C++
1
https://gitee.com/balloonwj/CppGuide.git
git@gitee.com:balloonwj/CppGuide.git
balloonwj
CppGuide
CppGuide
master

搜索帮助