2014-11-19 00:25:21 +08:00
|
|
|
|
#ifndef ACL_SLICE_INCLUDE_H
|
|
|
|
|
#define ACL_SLICE_INCLUDE_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "acl_define.h"
|
|
|
|
|
|
|
|
|
|
#define ACL_SLICE_FLAG_OFF (0)
|
|
|
|
|
#define ACL_SLICE_FLAG_GC1 (1 << 0) /**< <20>ռ<EFBFBD><D5BC><EFBFBD>ʡ, <20><> gc <20><><EFBFBD>ܲ<EFBFBD> */
|
|
|
|
|
#define ACL_SLICE_FLAG_GC2 (1 << 1) /**< <20>ռ<EFBFBD><D5BC>е<EFBFBD>, gc <20>ȽϺ<C8BD> */
|
|
|
|
|
#define ACL_SLICE_FLAG_GC3 (1 << 2) /**< <20>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>, gc ֻ<><D6BB>˳<EFBFBD><CBB3>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> */
|
|
|
|
|
#define ACL_SLICE_FLAG_RTGC_OFF (1 << 10) /**< <20>ر<EFBFBD>ʵʱ<CAB5>ڴ<EFBFBD><DAB4>ͷ<EFBFBD> */
|
|
|
|
|
#define ACL_SLICE_FLAG_LP64_ALIGN (1 << 11) /**< <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>64λƽ̨<C6BD><CCA8>Ҫ<EFBFBD><D2AA>8<EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD> */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>Ƭ<EFBFBD>ص<EFBFBD>״̬<EFBFBD>ṹ
|
|
|
|
|
*/
|
|
|
|
|
typedef struct ACL_SLICE_STAT {
|
|
|
|
|
int nslots; /**< total slice count free in slots */
|
|
|
|
|
int islots; /**< current position of free slots slice */
|
|
|
|
|
int page_nslots; /**< count slice of each page */
|
|
|
|
|
int page_size; /**< length of each malloc */
|
|
|
|
|
int slice_length; /**< length of each slice from user's set */
|
|
|
|
|
int slice_size; /**< length of each slice really allocated */
|
|
|
|
|
int nbuf; /**< count of MEM_BUF allocated */
|
|
|
|
|
acl_uint64 length; /**< total size of all MEM_BUF's buf */
|
|
|
|
|
acl_uint64 used_length; /**< total size of used */
|
|
|
|
|
unsigned int flag; /**< same as the ACL_SLICE's flag been set when created */
|
|
|
|
|
} ACL_SLICE_STAT;
|
|
|
|
|
|
|
|
|
|
typedef struct ACL_SLICE ACL_SLICE;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param name {const char*} <EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param page_size {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>ʱ<EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>ҳ<EFBFBD><EFBFBD>С
|
|
|
|
|
* @param slice_size {int} ÿ<EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>Ĵ<EFBFBD>С
|
|
|
|
|
* @param flag {unsigned int} <EFBFBD><EFBFBD>־λ<EFBFBD><EFBFBD><EFBFBD>μ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ACL_SLICE_FLAG_xxx
|
|
|
|
|
* @return {ACL_SLICE*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
ACL_API ACL_SLICE *acl_slice_create(const char *name, int page_size,
|
|
|
|
|
int slice_size, unsigned int flag);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param slice {ACL_SLICE*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
ACL_API void acl_slice_destroy(ACL_SLICE *slice);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD>ٸ<EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD>ʹ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param slice {ACL_SLICE*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {int} >= 0, <EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD>ʹ<EFBFBD>õ<EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
ACL_API int acl_slice_used(ACL_SLICE *slice);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ
|
|
|
|
|
* @param slice {ACL_SLICE*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {void*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD>ַ
|
|
|
|
|
*/
|
|
|
|
|
ACL_API void *acl_slice_alloc(ACL_SLICE *slice);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD>ʼ<EFBFBD><EFBFBD>Ϊ0
|
|
|
|
|
* @param slice {ACL_SLICE*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {void*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD>ַ
|
|
|
|
|
*/
|
|
|
|
|
ACL_API void *acl_slice_calloc(ACL_SLICE *slice);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>ͷ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ
|
|
|
|
|
* @param slice {ACL_SLICE*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param ptr {void*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD>ַ, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> acl_slice_alloc/acl_slice_calloc <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
ACL_API void acl_slice_free2(ACL_SLICE *slice, void *ptr);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>ͷ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ
|
|
|
|
|
* @param ptr {void*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD><EFBFBD>ַ, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> acl_slice_alloc/acl_slice_calloc <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
ACL_API void acl_slice_free(void *ptr);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>鿴<EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>صĵ<EFBFBD>ǰ״̬
|
|
|
|
|
* @param slice {ACL_SLICE*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param sbuf {ACL_SLICE_STAT*} <EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
ACL_API void acl_slice_stat(ACL_SLICE *slice, ACL_SLICE_STAT *sbuf);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ز<EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
|
|
|
|
|
* @param slice {ACL_SLICE*} <EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param {int} <EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>Ƭ<EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0: <EFBFBD><EFBFBD>; 1: <EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
ACL_API int acl_slice_gc(ACL_SLICE *slice);
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
typedef struct ACL_SLICE_POOL {
|
|
|
|
|
ACL_SLICE **slices; /* the slice array */
|
|
|
|
|
int base; /* the base byte size */
|
|
|
|
|
int nslice; /* the max number of base size */
|
|
|
|
|
unsigned int slice_flag; /* flag: ACL_SLICE_FLAG_GC2[3] | ACL_SLICE_FLAG_RTGC_OFF */
|
|
|
|
|
} ACL_SLICE_POOL;
|
|
|
|
|
|
|
|
|
|
ACL_API void acl_slice_pool_init(ACL_SLICE_POOL *asp);
|
|
|
|
|
ACL_API ACL_SLICE_POOL *acl_slice_pool_create(int base, int nslice,
|
|
|
|
|
unsigned int slice_flag);
|
|
|
|
|
ACL_API void acl_slice_pool_destroy(ACL_SLICE_POOL *asp);
|
|
|
|
|
ACL_API int acl_slice_pool_used(ACL_SLICE_POOL *asp);
|
|
|
|
|
ACL_API void acl_slice_pool_clean(ACL_SLICE_POOL *asp);
|
|
|
|
|
ACL_API void acl_slice_pool_reset(ACL_SLICE_POOL *asp);
|
|
|
|
|
ACL_API void acl_slice_pool_free(const char *filename, int line, void *buf);
|
|
|
|
|
ACL_API void acl_slice_pool_gc(ACL_SLICE_POOL *asp);
|
|
|
|
|
ACL_API void *acl_slice_pool_alloc(const char *filename, int line,
|
|
|
|
|
ACL_SLICE_POOL *asp, size_t size);
|
|
|
|
|
ACL_API void *acl_slice_pool_calloc(const char *filename, int line,
|
|
|
|
|
ACL_SLICE_POOL *asp, size_t nmemb, size_t size);
|
|
|
|
|
ACL_API void *acl_slice_pool_realloc(const char *filename, int line,
|
|
|
|
|
ACL_SLICE_POOL *asp, void *ptr, size_t size);
|
|
|
|
|
ACL_API void *acl_slice_pool_memdup(const char *filename, int line,
|
|
|
|
|
ACL_SLICE_POOL *asp, const void *ptr, size_t len);
|
|
|
|
|
ACL_API char *acl_slice_pool_strdup(const char *filename, int line,
|
|
|
|
|
ACL_SLICE_POOL *asp, const char *str);
|
|
|
|
|
ACL_API char *acl_slice_pool_strndup(const char *filename, int line,
|
|
|
|
|
ACL_SLICE_POOL *asp, const char *str, size_t len);
|
|
|
|
|
|
2016-12-29 23:58:18 +08:00
|
|
|
|
ACL_API void acl_slice_mem_hook(void *(*malloc_hook)(const char*, int, size_t),
|
|
|
|
|
void *(*calloc_hook)(const char*, int, size_t, size_t),
|
|
|
|
|
void *(*realloc_hook)(const char*, int, void*, size_t),
|
|
|
|
|
void (*free_hook)(const char*, int, void*));
|
|
|
|
|
ACL_API void acl_slice_mem_unhook(void);
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|