apr内存池阅读笔记-结构体说明

来源:互联网 发布:直销软件开发制作 编辑:程序博客网 时间:2024/05/29 03:18

以注释的方式记录一下,方便自己回头学习与使用。
如有错误或者建议欢迎留言。

分配器allocator

struct apr_allocator_t {    apr_uint32_t        max_index;//分配器包含的最大节点内存大小    apr_uint32_t        max_free_index;//分配器能包含的最大内存    apr_uint32_t        current_free_index;//分配器当前还能接收的内存大小#if APR_HAS_THREADS    apr_thread_mutex_t *mutex;//锁,支持线程安全。#endif /* APR_HAS_THREADS */    apr_pool_t         *owner;//所属的内存池    /**    节点链表数组,数组索引代表了节点链表中的节点内存大小。    free[0]保存的大小是大于MAX_INDEX(这是个宏,不是分配器的成员变量,默认为20。)的节点。    数组结构如下:    free[0]:size  大于20*BOUNDARY_SIZE    free[1]:size  (1+1)*BOUNDARY_SIZE 8192    free[2]:size  (2+1)*BOUNDARY_SIZE 12288    ...    free[19]:size  (19+1)*BOUNDARY_SIZE 81920    */    apr_memnode_t      *free[MAX_INDEX];};

节点memnode

struct apr_memnode_t {     apr_memnode_t *next;            //下一个节点    apr_memnode_t **ref;            //指向的是链表中上一个节点的next指针    apr_uint32_t   index;           //节点的内存大小    apr_uint32_t   free_index;      //空闲内存大小    char          *first_avail;     //空闲内存起始地址    char          *endp;            //空闲内存结束地址};

内存池pool

struct apr_pool_t {    apr_pool_t           *parent;//父内存池    apr_pool_t           *child;//子内存池    apr_pool_t           *sibling;//兄弟内存池    apr_pool_t          **ref;//指向在兄弟链中的上一个内存池    cleanup_t            *cleanups;//清理函数相关,可以注册自定义清理函数。    cleanup_t            *free_cleanups;    apr_allocator_t      *allocator;//内存池使用的分配器    struct process_chain *subprocesses;    apr_abortfunc_t       abort_fn;//可自定义出错时的处理函数,如申请的内存大小非法,系统内存不足等错误。    apr_hash_t           *user_data;//hashmap可以存放自定义的键值对    const char           *tag;//一个字符串标识,在日志中可以起到标识作用。#if !APR_POOL_DEBUG    apr_memnode_t        *active;//活跃节点(已使用的节点)链表    apr_memnode_t        *self; //内存池本身所在的节点    char                 *self_first_avail;//内存池本身所在的节点的空闲内存起始地址#else /* APR_POOL_DEBUG */    apr_pool_t           *joined; /* the caller has guaranteed that this pool                                * will survive as long as ->joined */    debug_node_t         *nodes;    const char           *file_line;    apr_uint32_t          creation_flags;    unsigned int          stat_alloc;    unsigned int          stat_total_alloc;    unsigned int          stat_clear;#if APR_HAS_THREADS    apr_os_thread_t       owner;//所属线程    apr_thread_mutex_t   *mutex;//锁#endif /* APR_HAS_THREADS */#endif /* APR_POOL_DEBUG */#ifdef NETWARE    apr_os_proc_t         owner_proc;#endif /* defined(NETWARE) */    cleanup_t            *pre_cleanups;}; 
0 0
原创粉丝点击