src/cx/allocator.h

changeset 503
a89857072ace
parent 500
eb9e7bd40a8e
child 508
8aea65ae1eaf
equal deleted inserted replaced
502:33e7b6ebf403 503:a89857072ace
44 */ 44 */
45 typedef struct { 45 typedef struct {
46 /** 46 /**
47 * The allocator's malloc() implementation. 47 * The allocator's malloc() implementation.
48 */ 48 */
49 void *(*malloc)(void *data, size_t n); 49 void *(*malloc)(
50 void *data,
51 size_t n
52 );
50 53
51 /** 54 /**
52 * The allocator's realloc() implementation. 55 * The allocator's realloc() implementation.
53 */ 56 */
54 void *(*realloc)(void *data, void *mem, size_t n) 57 void *(*realloc)(
58 void *data,
59 void *mem,
60 size_t n
61 )
55 __attribute__((__warn_unused_result__)); 62 __attribute__((__warn_unused_result__));
56 63
57 /** 64 /**
58 * The allocator's calloc() implementation. 65 * The allocator's calloc() implementation.
59 */ 66 */
60 void *(*calloc)(void *data, size_t nelem, size_t n); 67 void *(*calloc)(
68 void *data,
69 size_t nelem,
70 size_t n
71 );
61 72
62 /** 73 /**
63 * The allocator's free() implementation. 74 * The allocator's free() implementation.
64 */ 75 */
65 void (*free)(void *data, void *mem) 76 void (*free)(
77 void *data,
78 void *mem
79 )
66 __attribute__((__nonnull__)); 80 __attribute__((__nonnull__));
67 } cx_allocator_class; 81 } cx_allocator_class;
68 82
69 /** 83 /**
70 * Structure holding the data for an allocator. 84 * Structure holding the data for an allocator.
87 101
88 /** 102 /**
89 * A default allocator using standard library malloc() etc. 103 * A default allocator using standard library malloc() etc.
90 */ 104 */
91 extern CxAllocator *cxDefaultAllocator; 105 extern CxAllocator *cxDefaultAllocator;
106
107 /**
108 * Function pointer type for destructor functions.
109 *
110 * A destructor function deallocates possible contents and MAY free the memory
111 * pointed to by \p memory.
112 *
113 * @param memory a pointer to the object to destruct
114 * @return \p memory if it has NOT been free'd by this destructor, otherwise \c NULL
115 */
116 typedef void *(*cx_destructor_func)(void *memory)
117 __attribute__((__nonnull__, __warn_unused_result__));
92 118
93 /** 119 /**
94 * Allocate \p n bytes of memory. 120 * Allocate \p n bytes of memory.
95 * 121 *
96 * @param allocator the allocator 122 * @param allocator the allocator

mercurial