| 218 #include <cx/buffer.h> |
218 #include <cx/buffer.h> |
| 219 |
219 |
| 220 void cxBufferReset(CxBuffer *buffer); |
220 void cxBufferReset(CxBuffer *buffer); |
| 221 |
221 |
| 222 void cxBufferClear(CxBuffer *buffer); |
222 void cxBufferClear(CxBuffer *buffer); |
| |
223 |
| |
224 size_t cxBufferPop(CxBuffer *buffer, |
| |
225 size_t size, size_t nitems); |
| 223 ``` |
226 ``` |
| 224 |
227 |
| 225 The function `cxBufferReset()` sets both size and position of the buffer to zero, |
228 The function `cxBufferReset()` sets both size and position of the buffer to zero, |
| 226 and `cxBufferClear()` additionally uses `memset()` to set every byte in the buffer to zero. |
229 and `cxBufferClear()` additionally uses `memset()` to set every byte in the buffer to zero. |
| 227 |
230 |
| 228 > When clearing the buffer, only the "live" data, i.e., bytes with indices `[0..size)`, are cleared. |
231 > When clearing the buffer, only the "live" data, i.e., bytes with indices `[0..size)`, are cleared. |
| 229 > If you want to clear the entire buffer's memory, you would need to set the size to the capacity, first. |
232 > If you want to clear the entire buffer's memory, you would need to set the size to the capacity, first. |
| |
233 |
| |
234 The function `cxBufferPop()` erases the last `nitems` with the given `size` and returns the number of items that could be erased. |
| |
235 When the buffer contains fewer bytes than requested and the number of bytes is not divisible by the item `size`, |
| |
236 the remainder will stay in the buffer. |
| 230 |
237 |
| 231 > If the `CX_BUFFER_COPY_ON_WRITE` flag is set, `cxBufferClear()` behaves exactly like `cxBufferReset()`, |
238 > If the `CX_BUFFER_COPY_ON_WRITE` flag is set, `cxBufferClear()` behaves exactly like `cxBufferReset()`, |
| 232 > because writing to the contents is disallowed. |
239 > because writing to the contents is disallowed. |
| 233 >{style="note"} |
240 >{style="note"} |
| 234 |
241 |