Buf - Dynamic Buffer Module
The RBuf module is a flexible, dynamic growable buffer structure that is ideal as a network and file buffer.
RBuf has start and end pointers to the data buffer which act as read/write pointers. Routines are provided to get and put data into and out of the buffer and automatically advance the appropriate start/end pointer. By definition, the buffer is empty when the start pointer == the end pointer.
Buffers can be created with a fixed size or can grow dynamically as more data is added to the buffer.
For performance, the specification of RBuf is deliberately exposed. All members of RBuf are implicitly public. However, it is still recommended that wherever possible, you use the accessor routines provided.
- Dynamically growable memory buffer
- Routines to get references to start and end pointers
- Option to null terminate the buffer
- Formatted add to buffer
The RBuf definition is:
API Quick Tour
To create a buffer with an initial size. Set the size to zero for a default size of 4K.
To add data to the buffer. It will automatically grow as required.
To get the buffer length
Note: ssize is a typedef from "osdep.h" for ssize_t which is a 64-bit signed quantity.
To add a NULL character to the buffer without moving the end pointer. i.e.
To explicitly grow the buffer:
To see how much space is available in the buffer. This is (endbuf - end).
To get a reference to the end of the buffer:
To adjust the start or the end:
To copy data out of the buffer, reference the start pointer and adjust:
To empty the buffer:
The full API is specified here: