hat-util  0.6.14
Utility library
allocator.h
Go to the documentation of this file.
1 #ifndef HAT_ALLOCATOR_H
2 #define HAT_ALLOCATOR_H
3 
8 #include <stddef.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 typedef struct hat_allocator_t hat_allocator_t;
15 
28 typedef void *(*hat_allocator_realloc_t)(hat_allocator_t *a, size_t size,
29  void *old);
30 
39 };
40 
41 
49 static inline void *hat_allocator_alloc(hat_allocator_t *a, size_t size) {
50  return a->realloc(a, size, NULL);
51 }
52 
61 static inline void *hat_allocator_realloc(hat_allocator_t *a, size_t size,
62  void *old) {
63  return a->realloc(a, size, old);
64 }
65 
70 static inline void hat_allocator_free(hat_allocator_t *a, void *old) {
71  a->realloc(a, 0, old);
72 }
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif
void *(* hat_allocator_realloc_t)(hat_allocator_t *a, size_t size, void *old)
Custom allocator implementation function.
Definition: allocator.h:28
static void hat_allocator_free(hat_allocator_t *a, void *old)
Free memory block.
Definition: allocator.h:70
static void * hat_allocator_alloc(hat_allocator_t *a, size_t size)
Allocate new memory block.
Definition: allocator.h:49
static void * hat_allocator_realloc(hat_allocator_t *a, size_t size, void *old)
Reallocate existing memory block.
Definition: allocator.h:61
Allocator base struct.
Definition: allocator.h:36
hat_allocator_realloc_t realloc
custom realloc implementation
Definition: allocator.h:38