ucx/cx/buffer.h

changeset 1016
ccde46662db7
parent 995
2f811eae2424
equal deleted inserted replaced
1015:b459361d98ad 1016:ccde46662db7
166 * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying 166 * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying
167 * copy-on-write should be avoided, because the allocated 167 * copy-on-write should be avoided, because the allocated
168 * space will be leaking after the copy-on-write operation. 168 * space will be leaking after the copy-on-write operation.
169 * 169 *
170 * @param buffer the buffer to initialize 170 * @param buffer the buffer to initialize
171 * @param allocator the allocator this buffer shall use for automatic
172 * memory management
173 * (if @c NULL, the cxDefaultAllocator will be used)
171 * @param space pointer to the memory area, or @c NULL to allocate 174 * @param space pointer to the memory area, or @c NULL to allocate
172 * new memory 175 * new memory
173 * @param capacity the capacity of the buffer 176 * @param capacity the capacity of the buffer
174 * @param allocator the allocator this buffer shall use for automatic
175 * memory management
176 * (if @c NULL, the cxDefaultAllocator will be used)
177 * @param flags buffer features (see cx_buffer_s.flags) 177 * @param flags buffer features (see cx_buffer_s.flags)
178 * @return zero on success, non-zero if a required allocation failed 178 * @return zero on success, non-zero if a required allocation failed
179 */ 179 */
180 cx_attr_nonnull_arg(1) 180 cx_attr_nonnull_arg(1)
181 CX_EXPORT int cxBufferInit(CxBuffer *buffer, void *space, size_t capacity, 181 CX_EXPORT int cxBufferInit(CxBuffer *buffer, const CxAllocator *allocator,
182 const CxAllocator *allocator, int flags); 182 void *space, size_t capacity, int flags);
183 183
184 /** 184 /**
185 * Destroys the buffer contents. 185 * Destroys the buffer contents.
186 * 186 *
187 * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled. 187 * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled.
217 * 217 *
218 * @note You may provide @c NULL as the argument for @p space. 218 * @note You may provide @c NULL as the argument for @p space.
219 * Then this function will allocate the space and enforce 219 * Then this function will allocate the space and enforce
220 * the #CX_BUFFER_FREE_CONTENTS flag. 220 * the #CX_BUFFER_FREE_CONTENTS flag.
221 * 221 *
222 * @param allocator the allocator to use for allocating the structure and the automatic
223 * memory management within the buffer
224 * (if @c NULL, the cxDefaultAllocator will be used)
222 * @param space pointer to the memory area, or @c NULL to allocate 225 * @param space pointer to the memory area, or @c NULL to allocate
223 * new memory 226 * new memory
224 * @param capacity the capacity of the buffer 227 * @param capacity the capacity of the buffer
225 * @param allocator the allocator to use for allocating the structure and the automatic
226 * memory management within the buffer
227 * (if @c NULL, the cxDefaultAllocator will be used)
228 * @param flags buffer features (see cx_buffer_s.flags) 228 * @param flags buffer features (see cx_buffer_s.flags)
229 * @return a pointer to the buffer on success, @c NULL if a required allocation failed 229 * @return a pointer to the buffer on success, @c NULL if a required allocation failed
230 */ 230 */
231 cx_attr_malloc cx_attr_dealloc(cxBufferFree, 1) cx_attr_nodiscard 231 cx_attr_malloc cx_attr_dealloc(cxBufferFree, 1) cx_attr_nodiscard
232 CX_EXPORT CxBuffer *cxBufferCreate(void *space, size_t capacity, 232 CX_EXPORT CxBuffer *cxBufferCreate(const CxAllocator *allocator, void *space,
233 const CxAllocator *allocator, int flags); 233 size_t capacity, int flags);
234 234
235 /** 235 /**
236 * Shifts the contents of the buffer by the given offset. 236 * Shifts the contents of the buffer by the given offset.
237 * 237 *
238 * If the offset is positive, the contents are shifted to the right. 238 * If the offset is positive, the contents are shifted to the right.

mercurial