more
This commit is contained in:
parent
17578d2427
commit
e495508337
|
@ -104,77 +104,4 @@ static size_t haUsage(SMemAllocator *pma) { return ((SHeapAllocator *)(pma->impl
|
||||||
/* ------------------------ ARENA ALLOCATOR ------------------------ */
|
/* ------------------------ ARENA ALLOCATOR ------------------------ */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t usage;
|
size_t usage;
|
||||||
} SArenaAllocator;
|
} 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
|
|
Loading…
Reference in New Issue