62 * @param data the allocator's data |
62 * @param data the allocator's data |
63 * @param mem pointer to the previously allocated block |
63 * @param mem pointer to the previously allocated block |
64 * @param n the new size in bytes |
64 * @param n the new size in bytes |
65 * @return a pointer to the re-allocated memory |
65 * @return a pointer to the re-allocated memory |
66 */ |
66 */ |
67 void *(*realloc)(void *data, void *mem, size_t n); |
67 void *(*realloc)(void *data, void *mem, size_t n) |
|
68 __attribute__((__warn_unused_result__)); |
68 |
69 |
69 /** |
70 /** |
70 * Allocate \p nelem elements of \p n bytes each, all initialized to zero. |
71 * Allocate \p nelem elements of \p n bytes each, all initialized to zero. |
71 * |
72 * |
72 * @param data the allocator's data |
73 * @param data the allocator's data |
82 * \note Freeing a block of a different allocator is undefined. |
83 * \note Freeing a block of a different allocator is undefined. |
83 * |
84 * |
84 * @param data the allocator's data |
85 * @param data the allocator's data |
85 * @param mem a pointer to the block to free |
86 * @param mem a pointer to the block to free |
86 */ |
87 */ |
87 void (*free)(void *data, void *mem); |
88 void (*free)(void *data, void *mem) |
|
89 __attribute__((__nonnull__)); |
88 } cx_allocator_class; |
90 } cx_allocator_class; |
89 |
91 |
90 /** |
92 /** |
91 * Structure holding the data for an allocator. |
93 * Structure holding the data for an allocator. |
92 */ |
94 */ |
116 * |
118 * |
117 * @param allocator the allocator |
119 * @param allocator the allocator |
118 * @param n the number of bytes |
120 * @param n the number of bytes |
119 * @return a pointer to the allocated memory |
121 * @return a pointer to the allocated memory |
120 */ |
122 */ |
121 __attribute__ ((malloc)) |
123 void *cxMalloc(CxAllocator allocator, size_t n) |
122 void *cxMalloc(CxAllocator allocator, size_t n); |
124 __attribute__((__malloc__)); |
123 |
125 |
124 /** |
126 /** |
125 * Re-allocate the previously allocated block in \p mem, making the new block \p n bytes long. |
127 * Re-allocate the previously allocated block in \p mem, making the new block \p n bytes long. |
126 * This function may return the same pointer that was passed to it, if moving the memory |
128 * This function may return the same pointer that was passed to it, if moving the memory |
127 * was not necessary. |
129 * was not necessary. |
131 * @param allocator the allocator |
133 * @param allocator the allocator |
132 * @param mem pointer to the previously allocated block |
134 * @param mem pointer to the previously allocated block |
133 * @param n the new size in bytes |
135 * @param n the new size in bytes |
134 * @return a pointer to the re-allocated memory |
136 * @return a pointer to the re-allocated memory |
135 */ |
137 */ |
136 void *cxRealloc(CxAllocator allocator, void *mem, size_t n); |
138 void *cxRealloc(CxAllocator allocator, void *mem, size_t n) |
|
139 __attribute__((warn_unused_result)); |
137 |
140 |
138 /** |
141 /** |
139 * Re-allocate a previously allocated block and changes the pointer in-place, if necessary. |
142 * Re-allocate a previously allocated block and changes the pointer in-place, if necessary. |
140 * This function acts like cxRealloc() using the pointer pointed to by \p mem. |
143 * This function acts like cxRealloc() using the pointer pointed to by \p mem. |
141 * On success, the pointer is changed to the new location (in case the |
144 * On success, the pointer is changed to the new location (in case the |
148 * @param allocator the allocator |
151 * @param allocator the allocator |
149 * @param mem pointer to the pointer to allocated block |
152 * @param mem pointer to the pointer to allocated block |
150 * @param n the new size in bytes |
153 * @param n the new size in bytes |
151 * @return zero on success, non-zero on failure |
154 * @return zero on success, non-zero on failure |
152 */ |
155 */ |
153 __attribute__ ((nonnull)) |
156 int cxReallocate(CxAllocator allocator, void **mem, size_t n) |
154 int cxReallocate(CxAllocator allocator, void **mem, size_t n); |
157 __attribute__((nonnull)); |
155 |
158 |
156 /** |
159 /** |
157 * Allocate \p nelem elements of \p n bytes each, all initialized to zero. |
160 * Allocate \p nelem elements of \p n bytes each, all initialized to zero. |
158 * |
161 * |
159 * @param allocator the allocator |
162 * @param allocator the allocator |
160 * @param nelem the number of elements |
163 * @param nelem the number of elements |
161 * @param n the size of each element in bytes |
164 * @param n the size of each element in bytes |
162 * @return a pointer to the allocated memory |
165 * @return a pointer to the allocated memory |
163 */ |
166 */ |
164 __attribute__ ((malloc)) |
167 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n) |
165 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n); |
168 __attribute__((malloc)); |
166 |
169 |
167 /** |
170 /** |
168 * Free a block allocated by this allocator. |
171 * Free a block allocated by this allocator. |
169 * |
172 * |
170 * \note Freeing a block of a different allocator is undefined. |
173 * \note Freeing a block of a different allocator is undefined. |
171 * |
174 * |
172 * @param allocator the allocator |
175 * @param allocator the allocator |
173 * @param mem a pointer to the block to free |
176 * @param mem a pointer to the block to free |
174 */ |
177 */ |
175 __attribute__((nonnull)) |
178 void cxFree(CxAllocator allocator, void *mem) |
176 void cxFree(CxAllocator allocator, void *mem); |
179 __attribute__((nonnull)); |
177 |
180 |
178 #ifdef __cplusplus |
181 #ifdef __cplusplus |
179 } /* extern "C" */ |
182 } /* extern "C" */ |
180 #endif |
183 #endif |
181 |
184 |