src/cx/allocator.h

changeset 452
a10c3e127050
parent 450
7960298039cf
child 461
005c2791c2e2
equal deleted inserted replaced
451:db06dda7ac4d 452:a10c3e127050
119 * @param allocator the allocator 119 * @param allocator the allocator
120 * @param n the number of bytes 120 * @param n the number of bytes
121 * @return a pointer to the allocated memory 121 * @return a pointer to the allocated memory
122 */ 122 */
123 void *cxMalloc(CxAllocator allocator, size_t n) 123 void *cxMalloc(CxAllocator allocator, size_t n)
124 __attribute__((__malloc__)); 124 __attribute__((__malloc__, __alloc_size__(2)));
125 125
126 /** 126 /**
127 * 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.
128 * 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
129 * was not necessary. 129 * was not necessary.
134 * @param mem pointer to the previously allocated block 134 * @param mem pointer to the previously allocated block
135 * @param n the new size in bytes 135 * @param n the new size in bytes
136 * @return a pointer to the re-allocated memory 136 * @return a pointer to the re-allocated memory
137 */ 137 */
138 void *cxRealloc(CxAllocator allocator, void *mem, size_t n) 138 void *cxRealloc(CxAllocator allocator, void *mem, size_t n)
139 __attribute__((warn_unused_result)); 139 __attribute__((__warn_unused_result__, __alloc_size__(3)));
140 140
141 /** 141 /**
142 * 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.
143 * 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.
144 * 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
152 * @param mem pointer to the pointer to allocated block 152 * @param mem pointer to the pointer to allocated block
153 * @param n the new size in bytes 153 * @param n the new size in bytes
154 * @return zero on success, non-zero on failure 154 * @return zero on success, non-zero on failure
155 */ 155 */
156 int cxReallocate(CxAllocator allocator, void **mem, size_t n) 156 int cxReallocate(CxAllocator allocator, void **mem, size_t n)
157 __attribute__((nonnull)); 157 __attribute__((__nonnull__));
158 158
159 /** 159 /**
160 * 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.
161 * 161 *
162 * @param allocator the allocator 162 * @param allocator the allocator
163 * @param nelem the number of elements 163 * @param nelem the number of elements
164 * @param n the size of each element in bytes 164 * @param n the size of each element in bytes
165 * @return a pointer to the allocated memory 165 * @return a pointer to the allocated memory
166 */ 166 */
167 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n) 167 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n)
168 __attribute__((malloc)); 168 __attribute__((__malloc__, __alloc_size__(2, 3)));
169 169
170 /** 170 /**
171 * Free a block allocated by this allocator. 171 * Free a block allocated by this allocator.
172 * 172 *
173 * \note Freeing a block of a different allocator is undefined. 173 * \note Freeing a block of a different allocator is undefined.
174 * 174 *
175 * @param allocator the allocator 175 * @param allocator the allocator
176 * @param mem a pointer to the block to free 176 * @param mem a pointer to the block to free
177 */ 177 */
178 void cxFree(CxAllocator allocator, void *mem) 178 void cxFree(CxAllocator allocator, void *mem)
179 __attribute__((nonnull)); 179 __attribute__((__nonnull__));
180 180
181 #ifdef __cplusplus 181 #ifdef __cplusplus
182 } /* extern "C" */ 182 } /* extern "C" */
183 #endif 183 #endif
184 184

mercurial