第一天

来源:互联网 发布:被芯哪个牌子好 知乎 编辑:程序博客网 时间:2024/05/19 16:48

首先分析cache.c cache.h文件

首先头文件

包含pthread.h,这个与线程有关的头文件

定义一个构造分配的内存的构造函数指针类型,cache_constructor_t

定义一个返回到操作系统之前用于清理分配对象的函数指针类型,cache_destructor_t

typedef struct {
    /** Mutex to protect access to the structure */
    pthread_mutex_t mutex; 用于保护整个结构体的互斥量
    /** Name of the cache objects in this cache (provided by the caller) */
    char *name; 缓冲区的对象名字
    /** List of pointers to available buffers in this cache */
    void **ptr; 指向可用缓冲区中可用的缓存地址
    /** The size of each element in this cache */
    size_t bufsize; 每个缓冲区中元素大小
    /** The capacity of the list of elements */
    int freetotal; 一共有多少个缓存
    /** The current number of free elements */
    int freecurr; 目前多少个没有被使用的缓存
    /** The constructor to be called each time we allocate more memory */
    cache_constructor_t* constructor; 构造函数
    /** The destructor to be called each time before we release memory */
    cache_destructor_t* destructor; 析构函数
} cache_t;


cache_create 创建一个缓存对象

cache_destroy 销毁一个缓存对象

cache_alloc 从缓冲区分配一个对象

cache_free 将对象返回到缓冲区



以下是assoc.c文件


定义一个64位的redzone_pattern常量,不知道用来干嘛的。

定义整形常量initial_pool_size 为64


cache_create


0 0
原创粉丝点击