116 * |
116 * |
117 * @param allocator the allocator |
117 * @param allocator the allocator |
118 * @param n the number of bytes |
118 * @param n the number of bytes |
119 * @return a pointer to the allocated memory |
119 * @return a pointer to the allocated memory |
120 */ |
120 */ |
|
121 __attribute__ ((malloc)) |
121 void *cxMalloc(CxAllocator allocator, size_t n); |
122 void *cxMalloc(CxAllocator allocator, size_t n); |
122 |
123 |
123 /** |
124 /** |
124 * Re-allocate the previously allocated block in \p mem, making the new block \p n bytes long. |
125 * Re-allocate the previously allocated block in \p mem, making the new block \p n bytes long. |
125 * This function may return the same pointer that was passed to it, if moving the memory |
126 * This function may return the same pointer that was passed to it, if moving the memory |
147 * @param allocator the allocator |
148 * @param allocator the allocator |
148 * @param mem pointer to the pointer to allocated block |
149 * @param mem pointer to the pointer to allocated block |
149 * @param n the new size in bytes |
150 * @param n the new size in bytes |
150 * @return zero on success, non-zero on failure |
151 * @return zero on success, non-zero on failure |
151 */ |
152 */ |
|
153 __attribute__ ((nonnull)) |
152 int cxReallocate(CxAllocator allocator, void **mem, size_t n); |
154 int cxReallocate(CxAllocator allocator, void **mem, size_t n); |
153 |
155 |
154 /** |
156 /** |
155 * Allocate \p nelem elements of \p n bytes each, all initialized to zero. |
157 * Allocate \p nelem elements of \p n bytes each, all initialized to zero. |
156 * |
158 * |
157 * @param allocator the allocator |
159 * @param allocator the allocator |
158 * @param nelem the number of elements |
160 * @param nelem the number of elements |
159 * @param n the size of each element in bytes |
161 * @param n the size of each element in bytes |
160 * @return a pointer to the allocated memory |
162 * @return a pointer to the allocated memory |
161 */ |
163 */ |
|
164 __attribute__ ((malloc)) |
162 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n); |
165 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n); |
163 |
166 |
164 /** |
167 /** |
165 * Free a block allocated by this allocator. |
168 * Free a block allocated by this allocator. |
166 * |
169 * |
167 * \note Freeing a block of a different allocator is undefined. |
170 * \note Freeing a block of a different allocator is undefined. |
168 * |
171 * |
169 * @param allocator the allocator |
172 * @param allocator the allocator |
170 * @param mem a pointer to the block to free |
173 * @param mem a pointer to the block to free |
171 */ |
174 */ |
|
175 __attribute__((nonnull)) |
172 void cxFree(CxAllocator allocator, void *mem); |
176 void cxFree(CxAllocator allocator, void *mem); |
173 |
177 |
174 #ifdef __cplusplus |
178 #ifdef __cplusplus |
175 } /* extern "C" */ |
179 } /* extern "C" */ |
176 #endif |
180 #endif |