提交 a37a59e1 编写于 作者: H Hongze Cheng

refact

上级 2834b3a6
......@@ -24,31 +24,20 @@ extern "C" {
typedef struct SMemAllocator SMemAllocator;
#define MALLOCATOR_APIS \
void *impl; \
void *(*malloc)(SMemAllocator *, size_t size); \
void *(*calloc)(SMemAllocator *, size_t nmemb, size_t size); \
void *(*realloc)(SMemAllocator *, void *ptr, size_t size); \
void (*free)(SMemAllocator *, void *ptr); \
size_t (*usage)(SMemAllocator *);
struct SMemAllocator {
MALLOCATOR_APIS
void *impl;
void *(*malloc)(SMemAllocator *, uint64_t size);
void *(*calloc)(SMemAllocator *, uint64_t nmemb, uint64_t size);
void *(*realloc)(SMemAllocator *, void *ptr, uint64_t size);
void (*free)(SMemAllocator *, void *ptr);
uint64_t (*usage)(SMemAllocator *);
};
// heap allocator
SMemAllocator *tdCreateHeapAllocator();
void tdDestroyHeapAllocator(SMemAllocator *pMemAllocator);
// arena allocator
SMemAllocator *tdCreateArenaAllocator(size_t size);
void tdDestroyArenaAllocator(SMemAllocator *);
#define mMalloc(pMemAllocator, size) (*(pMemAllocator->malloc))(pMemAllocator, size)
#define mCalloc(pMemAllocator, nmemb, size) (*(pMemAllocator->calloc))(pMemAllocator, nmemb, size)
#define mRealloc(pMemAllocator, ptr, size) (*(pMemAllocator->realloc))(pMemAllocator, ptr, size)
#define mFree(pMemAllocator, ptr) (*(pMemAllocator->free))(pMemAllocator, ptr)
#define mUsage(pMemAllocator) (*(pMemAllocator->usage))(pMemAllocator)
typedef struct {
void *impl;
SMemAllocator *(*create)();
void (*destroy)(SMemAllocator *);
} SMemAllocatorFactory;
#ifdef __cplusplus
}
......
......@@ -16,11 +16,16 @@
#ifndef _TD_TSDB_MEM_TABLE_H_
#define _TD_TSDB_MEM_TABLE_H_
#include "tsdb.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SMemTable SMemTable;
typedef struct SMemTable {
/* TODO */
SMemAllocator *pma;
} SMemTable;
#ifdef __cplusplus
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册