gSoap源码中Alist的使用
来源:互联网 发布:windows水印在哪里 编辑:程序博客网 时间:2024/06/05 15:39
- gSoap源码中Alist的使用
- 特点
gSoap源码中Alist的使用
typedef struct ALIST_S{ void *memlist; pthread_mutex_t mutex;}ALIST_T;#define SOAP_MAXALLOCSIZE (0) // 无限制#define SOAP_CANARY (0xC0DE)int alist_init(ALIST_T *list);void *soap_malloc(ALIST_T *list, size_t n);void *alist_calloc(ALIST_T *list, size_t n);char *alist_strdup(ALIST_T *list, const char *s);void alist_dealloc(ALIST_T *list, void *p);void alist_uninit(ALIST_T *list);void echo_alist(ALIST_T *list);源码int alist_init(ALIST_T *list){ int iRet = 0; if (list) { list->memlist = NULL; pthread_mutex_init(&list->mutex, NULL); } else { iRet = -1; } return iRet;}void* alist_calloc(ALIST_T *list, size_t n){ char *p; if (SOAP_MAXALLOCSIZE > 0 && n > SOAP_MAXALLOCSIZE) return NULL; if (n + sizeof(short) < n) return NULL; n += sizeof(short); if (n + ((-(long)n) & (sizeof(void*)-1)) + sizeof(void*) + sizeof(size_t) < n) return NULL; n += (-(long)n) & (sizeof(void*)-1); /* align at 4-, 8- or 16-byte boundary by rounding up */ p = (char*)SOAP_CALLOC(n + sizeof(void*) + sizeof(size_t)); if (!p) { return NULL; } /* set a canary word to detect memory overruns and data corruption */ *(unsigned short*)(p + n - sizeof(unsigned short)) = (unsigned short)SOAP_CANARY; /* keep chain of alloced cells for destruction */ pthread_mutex_lock(&list->mutex); *(void**)(p + n) = list->memlist; *(size_t*)(p + n + sizeof(void*)) = n; list->memlist = p + n; PRINT_Y("[%d]List:%x", n, *list); pthread_mutex_unlock(&list->mutex); return p;}char *alist_strdup(ALIST_T *list, const char *s){ char *t = NULL; if (s) { size_t n = strlen(s) + 1; if (n > 0) { t = (char*)alist_calloc(list, n); if (t) { memcpy((void*)t, (const void*)s, n); t[n - 1] = '\0'; } } } return t;}void alist_dealloc(ALIST_T *list, void *p){ if (list) { pthread_mutex_lock(&list->mutex); if (p) { char **q; for (q = (char **)(void *)&list->memlist; *q; q = *(char***)q) { if (*(unsigned short*)(char*)(*q - sizeof(unsigned short)) != (unsigned short)SOAP_CANARY) { pthread_mutex_unlock(&list->mutex); return; } if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*)))) { *q = **(char***)q; SOAP_FREE(p); pthread_mutex_unlock(&list->mutex); return; } } } else { char *q; while (list->memlist) { q = (char*)list->memlist; if (*(unsigned short*)(char*)(q - sizeof(unsigned short)) != (unsigned short)SOAP_CANARY) { pthread_mutex_unlock(&list->mutex); return; } *list = *(void**)q; q -= *(size_t*)(q + sizeof(void*)); SOAP_FREE(p); } } pthread_mutex_unlock(&list->mutex); } return;}void alist_uninit(ALIST_T *list){ if (list) { alist_dealloc(list, NULL); pthread_mutex_destroy(&list->mutex); } return ;}void alist_echo(ALIST_T *list){ char *q; char *tmp; int index = 0; if (list) { pthread_mutex_lock(&list->mutex); tmp = list->memlist; while(tmp) { q = (char*)tmp; if (*(unsigned short*)(char*)(q-sizeof(unsigned short)) != (unsigned short)SOAP_CANARY) { pthread_mutex_unlock(&list->mutex); return; } tmp = *(void**)q; q -= *(size_t*)(q + sizeof(void*)); index ++; } pthread_mutex_unlock(&list->mutex); } return ;}
特点
1.代码结构简洁
2.可以对多指针的结构体进行统一分配和释放
3.分配和释放添加锁
阅读全文
0 0
- gSoap源码中Alist的使用
- gSOAP中内存的使用
- gSOAP中内存的使用
- gSOAP的使用
- gSoap的使用
- gSOAP的使用
- gsoap的使用
- gSOAP的使用
- gSOAP的使用一
- gsoap的第一次使用
- gSoap的使用
- gsoap工具的使用
- Gsoap的简单使用
- 使用GSOAP的笔记
- gsoap 的教程和使用
- gSoap的简易使用流程
- linux下gsoap的使用
- onvif gsoap 工具的使用
- SQL经典判断语句实例
- 利用Bitvise SSH Client设置二级代理
- 第一次作业。
- springMVC前台数据传不到后台的解决办法
- Ibatis+DBCP+Mysql数据库访问
- gSoap源码中Alist的使用
- 合并两个单调递增的链表,使得合并后的链表也是有序
- 1028. 人口普查(20)
- 基于WebStorm, React和Ant.Design开发WebAppDemo
- 关于Spring的注解@Resource的问题
- get set 注解 以及public属性 依赖注入该怎么写
- CMake生成多个.so文件
- 机器学习(1)监督学习和无监督学习
- 通过cglib实现动态代理