nginx 源码学习笔记(十二)——基本容器——ngx_buf

ngx_buf.{c|h}分为两种类型,一种是file,一种是memory。因此这里会有文件的一些操作域。

typedef void *            ngx_buf_tag_t;

typedef struct ngx_buf_s  ngx_buf_t;

struct ngx_buf_s {
    u_char          *pos;              //已经执行的数据位置
    u_char          *last;              //使用的内存的最后一个字节的指针
    off_t            file_pos;           //文件指针
    off_t            file_last;
    u_char          *start;         /* start of buffer */      //buffer开始指针
    u_char          *end;           /* end of buffer */      //buffer结束指针
    ngx_buf_tag_t    tag;                                 //buf属于哪个模块
    ngx_file_t      *file;
    ngx_buf_t       *shadow;
    /* the buf's content could be changed */
    unsigned         temporary:1;
    /*
     * the buf's content is in a memory cache or in a read only memory
     * and must not be changed
     */
    unsigned         memory:1;                           //在内存中是不能更改的
    /* the buf's content is mmap()ed and must not be changed */
    unsigned         mmap:1;                            //是否是mmap的内存
    unsigned         recycled:1;                          
    unsigned         in_file:1;                            //是否文件
    unsigned         flush:1;
    unsigned         sync:1;
    unsigned         last_buf:1;
    unsigned         last_in_chain:1;
    unsigned         last_shadow:1;
    unsigned         temp_file:1;
    /* STUB */ int   num;
};

这里具体用时再细做研究吧。。。这里做个标记以后补上

 

红黑树(网上抄的一段)
红黑树在ngx_rbtree.c和ngx_rbtree.h中实现。红黑树能够以O(log2n)的时间复杂度进行搜索、插入、删除操作。此外,由于它的设计,任何不平衡都会在三次旋转之内解决。当然,还有一些更好的,但实现起来更复杂的数据结构能够做到一步旋转之内达到平衡,但红黑树能够给我们一个比较“便宜”的解决方案。红黑树的算法时间复杂度和AVL相同,但统计性能比AVL树更高。当然,红黑树并不适应所有应用树的领域。如果数据基本上是静态的,那么让他们待在他们能够插入,并且不影响平衡的地方会具有更好的性能。如果数据完全是静态的,例如,做一个哈希表,性能可能会更好一些。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值