147 * |
147 * |
148 * @param buffer the buffer to initialize |
148 * @param buffer the buffer to initialize |
149 * @param space pointer to the memory area, or \c NULL to allocate |
149 * @param space pointer to the memory area, or \c NULL to allocate |
150 * new memory |
150 * new memory |
151 * @param capacity the capacity of the buffer |
151 * @param capacity the capacity of the buffer |
152 * @param allocator the allocator this buffer shall use for automatic memory management |
152 * @param allocator the allocator this buffer shall use for automatic |
|
153 * memory management. If \c NULL, the default heap allocator will be used. |
153 * @param flags buffer features (see cx_buffer_s.flags) |
154 * @param flags buffer features (see cx_buffer_s.flags) |
154 * @return zero on success, non-zero if a required allocation failed |
155 * @return zero on success, non-zero if a required allocation failed |
155 */ |
156 */ |
156 __attribute__((__nonnull__(1, 4))) |
157 __attribute__((__nonnull__(1))) |
157 int cxBufferInit( |
158 int cxBufferInit( |
158 CxBuffer *buffer, |
159 CxBuffer *buffer, |
159 void *space, |
160 void *space, |
160 size_t capacity, |
161 size_t capacity, |
161 CxAllocator const *allocator, |
162 CxAllocator const *allocator, |
162 int flags |
163 int flags |
163 ); |
164 ); |
164 |
165 |
165 /** |
166 /** |
|
167 * Allocates and initializes a fresh buffer. |
|
168 * |
|
169 * \note You may provide \c NULL as argument for \p space. |
|
170 * Then this function will allocate the space and enforce |
|
171 * the #CX_BUFFER_FREE_CONTENTS flag. |
|
172 * |
|
173 * @param space pointer to the memory area, or \c NULL to allocate |
|
174 * new memory |
|
175 * @param capacity the capacity of the buffer |
|
176 * @param allocator the allocator to use for allocating the structure and the automatic |
|
177 * memory management within the buffer. If \c NULL, the default heap allocator will be used. |
|
178 * @param flags buffer features (see cx_buffer_s.flags) |
|
179 * @return a pointer to the buffer on success, \c NULL if a required allocation failed |
|
180 */ |
|
181 CxBuffer *cxBufferCreate( |
|
182 void *space, |
|
183 size_t capacity, |
|
184 CxAllocator const *allocator, |
|
185 int flags |
|
186 ); |
|
187 |
|
188 /** |
166 * Destroys the buffer contents. |
189 * Destroys the buffer contents. |
167 * |
190 * |
168 * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled. |
191 * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled. |
|
192 * If you want to free the memory of the entire buffer, use cxBufferFree(). |
169 * |
193 * |
170 * @param buffer the buffer which contents shall be destroyed |
194 * @param buffer the buffer which contents shall be destroyed |
|
195 * @see cxBufferInit() |
171 */ |
196 */ |
172 __attribute__((__nonnull__)) |
197 __attribute__((__nonnull__)) |
173 void cxBufferDestroy(CxBuffer *buffer); |
198 void cxBufferDestroy(CxBuffer *buffer); |
|
199 |
|
200 /** |
|
201 * Deallocates the buffer. |
|
202 * |
|
203 * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys |
|
204 * the contents. If you \em only want to destroy the contents, use cxBufferDestroy(). |
|
205 * |
|
206 * @param buffer the buffer to deallocate |
|
207 * @see cxBufferCreate() |
|
208 */ |
|
209 __attribute__((__nonnull__)) |
|
210 void cxBufferFree(CxBuffer *buffer); |
174 |
211 |
175 /** |
212 /** |
176 * Shifts the contents of the buffer by the given offset. |
213 * Shifts the contents of the buffer by the given offset. |
177 * |
214 * |
178 * If the offset is positive, the contents are shifted to the right. |
215 * If the offset is positive, the contents are shifted to the right. |