欢迎使用CSDN-markdown编辑器

来源:互联网 发布:json remove 编辑:程序博客网 时间:2024/06/05 05:13

模块strong的阅读
根据官方的文档,该模块是用于存储任意结构的数据。
根据官方文档的描述,该模块主要应用了以下三个函数

int     HostStorageRegister (const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void(*Free)(void *))int     HostSetStorageById (Host *h, int id, void *ptr)void *  HostGetStorageById (Host *h, int id)

上诉三个函数分别定义在Host-strong.h和实现在Host-strong.c中
实际上上诉函数的实现是对在Util-stronge.h中定义的函数的包装

分析storage模块的实现细节

typedef struct StorageMapping_ {    const char *name;    StorageEnum type; // host, flow, tx, stream, ssn, etc该枚举类型的定义在Util-stronge.h文件中    unsigned int size;    void *(*Alloc)(unsigned int);    void (*Free)(void *);} StorageMapping;typedef struct StorageList_ {    StorageMapping map;    int id;    struct StorageList_ *next;} StorageList;

从其数据结构上来说,底层的实现其实是一个单链表

static StorageList *storage_list = NULL;//全局链表的头指针static int storage_max_id[STORAGE_MAX];//统计所有类型数量的数组static int storage_registraton_closed = 0;//一个全局的标记static StorageMapping **storage_map = NULL;//
0 0