40 lines
1.0 KiB
C
40 lines
1.0 KiB
C
#ifndef __ALLOC_DISPATCH_H__
|
|
#define __ALLOC_DISPATCH_H__
|
|
|
|
#define MEMORY_USE_DEFAULT 0
|
|
#define MEMORY_USE_MYMALLOC 1
|
|
#define MEMORY_USE_JEMALLOC 2
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdatomic.h>
|
|
#include "mempool.h"
|
|
|
|
typedef enum {
|
|
ALLOC_JEMALLOC,
|
|
ALLOC_MALLOC,
|
|
ALLOC_MYPOOL,
|
|
ALLOC_OTHER
|
|
} AllocatorType;
|
|
|
|
void kvs_set_alloc_type(AllocatorType mode);
|
|
AllocatorType kvs_get_alloc_type(void);
|
|
|
|
typedef enum {
|
|
MEMLEAK_DETECT_OFF = 0, // 关闭检测
|
|
MEMLEAK_DETECT_ON = 1 // 开启检测
|
|
} MemLeakDetectMode;
|
|
|
|
void kvs_set_memleak_detect(MemLeakDetectMode mode);
|
|
MemLeakDetectMode kvs_get_memleak_detect(void);
|
|
|
|
void *kvs_malloc_impl(size_t size);
|
|
void kvs_free_impl(void *ptr);
|
|
|
|
void *nMalloc(size_t size, const char * filename, const char *func, int line);
|
|
void nFree(void *ptr, const char * filename, const char *func, int line);
|
|
|
|
#define kvs_malloc(size) nMalloc (size , __FILE__, __func__, __LINE__)
|
|
#define kvs_free(ptr) nFree (ptr , __FILE__, __func__, __LINE__)
|
|
|
|
#endif |