#ifndef UCX_ALLOCATOR_H
#define UCX_ALLOCATOR_H
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
void *(*malloc)(
void *data,
size_t n
);
__attribute__((__warn_unused_result__))
void *(*realloc)(
void *data,
void *mem,
size_t n
);
void *(*calloc)(
void *data,
size_t nelem,
size_t n
);
__attribute__((__nonnull__))
void (*free)(
void *data,
void *mem
);
} cx_allocator_class;
struct cx_allocator_s {
cx_allocator_class *cl;
void *data;
};
typedef struct cx_allocator_s CxAllocator;
extern CxAllocator *cxDefaultAllocator;
__attribute__((__nonnull__))
typedef void (*cx_destructor_func)(
void *memory);
__attribute__((__nonnull__(
2)))
typedef void (*cx_destructor_func2)(
void *data,
void *memory
);
__attribute__((__nonnull__))
int cx_reallocate(
void **mem,
size_t n
);
__attribute__((__malloc__))
__attribute__((__alloc_size__(
2)))
void *cxMalloc(
const CxAllocator *allocator,
size_t n
);
__attribute__((__warn_unused_result__))
__attribute__((__alloc_size__(
3)))
void *cxRealloc(
const CxAllocator *allocator,
void *mem,
size_t n
);
__attribute__((__nonnull__))
int cxReallocate(
const CxAllocator *allocator,
void **mem,
size_t n
);
__attribute__((__malloc__))
__attribute__((__alloc_size__(
2,
3)))
void *cxCalloc(
const CxAllocator *allocator,
size_t nelem,
size_t n
);
__attribute__((__nonnull__))
void cxFree(
const CxAllocator *allocator,
void *mem
);
#ifdef __cplusplus
}
#endif
#endif