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

more

上级 17578d24
......@@ -104,77 +104,4 @@ static size_t haUsage(SMemAllocator *pma) { return ((SHeapAllocator *)(pma->impl
/* ------------------------ ARENA ALLOCATOR ------------------------ */
typedef struct {
size_t usage;
} SArenaAllocator;
#if 0
SMemAllocator *pDefaultMA;
typedef struct {
char name[64];
} SHeapAllocator;
static SHeapAllocator *haNew();
static void haDestroy(SHeapAllocator *pha);
static void * haMalloc(SMemAllocator *pMemAllocator, size_t size);
void * haCalloc(SMemAllocator *pMemAllocator, size_t nmemb, size_t size);
static void haFree(SMemAllocator *pMemAllocator, void *ptr);
SMemAllocator *tdCreateHeapAllocator() {
SMemAllocator *pMemAllocator = NULL;
pMemAllocator = (SMemAllocator *)calloc(1, sizeof(*pMemAllocator));
if (pMemAllocator == NULL) {
// TODO: handle error
return NULL;
}
pMemAllocator->impl = haNew();
if (pMemAllocator->impl == NULL) {
tdDestroyHeapAllocator(pMemAllocator);
return NULL;
}
pMemAllocator->malloc = haMalloc;
pMemAllocator->calloc = haCalloc;
pMemAllocator->realloc = NULL;
pMemAllocator->free = haFree;
pMemAllocator->usage = NULL;
return pMemAllocator;
}
void tdDestroyHeapAllocator(SMemAllocator *pMemAllocator) {
if (pMemAllocator) {
// TODO
}
}
/* ------------------------ STATIC METHODS ------------------------ */
static SHeapAllocator *haNew() {
SHeapAllocator *pha = NULL;
/* TODO */
return pha;
}
static void haDestroy(SHeapAllocator *pha) {
// TODO
}
static void *haMalloc(SMemAllocator *pMemAllocator, size_t size) {
void *ptr = NULL;
ptr = malloc(size);
if (ptr) {
}
return ptr;
}
void *haCalloc(SMemAllocator *pMemAllocator, size_t nmemb, size_t size) {
/* TODO */
return NULL;
}
static void haFree(SMemAllocator *pMemAllocator, void *ptr) { /* TODO */
}
#endif
\ No newline at end of file
} SArenaAllocator;
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册