#ifndef UCX_ALLOCATOR_H
#define UCX_ALLOCATOR_H
#include "ucx.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void*(*ucx_allocator_malloc)(
void *pool,
size_t n);
typedef void*(*ucx_allocator_calloc)(
void *pool,
size_t n,
size_t size);
typedef void*(*ucx_allocator_realloc)(
void *pool,
void *data,
size_t n);
typedef void(*ucx_allocator_free)(
void *pool,
void *data);
typedef struct {
void *pool;
ucx_allocator_malloc malloc;
ucx_allocator_calloc calloc;
ucx_allocator_realloc realloc;
ucx_allocator_free free;
} UcxAllocator;
UcxAllocator *ucx_default_allocator();
void *ucx_default_malloc(
void *ignore,
size_t n);
void *ucx_default_calloc(
void *ignore,
size_t n,
size_t size);
void *ucx_default_realloc(
void *ignore,
void *data,
size_t n);
void ucx_default_free(
void *ignore,
void *data);
#define almalloc(allocator, n) ((allocator)->malloc((allocator)->pool, n))
#define alcalloc(allocator, n, size) \
((allocator)->calloc((allocator)->pool, n, size))
#define alrealloc(allocator, ptr, n) \
((allocator)->realloc((allocator)->pool, ptr, n))
#define alfree(allocator, ptr) ((allocator)->free((allocator)->pool, ptr))
#define UCX_ALLOCATOR_DEFAULT {
NULL, \
ucx_default_malloc, ucx_default_calloc, ucx_default_realloc, \
ucx_default_free }
#ifdef __cplusplus
}
#endif
#endif