nginx中ngx_list的数据结构

今天没事了,在查看nginx源代码中看到ngx_list的结构,发现设计为链表数组的形式,不知道为何这样设计nginx

struct ngx_list_part_s {
    void             *elts;//指向数组的起始地址
    ngx_uint_t        nelts;//数组已经使用多少元素
    ngx_list_part_t  *next;//下一个链表元素的地址
};


typedef struct {
    ngx_list_part_t  *last;//指向链表最后一个数组元素
    ngx_list_part_t   part;//链表的首个数组元素
    size_t            size;//限制每个数组元素的占用的空间大小
    ngx_uint_t        nalloc; //链表中数组元素一旦分配以后是不可更改的,nalloc表示每一个ngx_list_part_t数组的容量,即最多可存储多少个数据
    ngx_pool_t       *pool;//链表中管理内存分配的内存池对象
} ngx_list_t;

 只实现三个方法:数组

ngx_list_t *ngx_list_create(ngx_pool_t *pool, ngx_uint_t n, size_t size);ui

static ngx_inline ngx_int_t ngx_list_init(ngx_list_t *list, ngx_pool_t *pool, ngx_uint_t n, size_t size);私有方法 在ngx_list_create中调用设计

void *ngx_list_push(ngx_list_t *list);对象

相关文章
相关标签/搜索