A dynamic, resizable and reference counted memory buffer. More...
#include <DynamicBuffer.h>
Public Member Functions | |
| DynamicBuffer (size_t initial_size=0, bool own_buffer=true) | |
| Constructor. More... | |
| ~DynamicBuffer () | |
| Destructor; releases the buffer if it "owns" it. More... | |
| size_t | remaining () const |
| Returns the size of the unused portion. More... | |
| size_t | fill () const |
| Returns the size of the used portion. More... | |
| bool | empty () const |
| Returns true if the buffer is empty. More... | |
| void | ensure (size_t len) |
| Ensure space for additional data Will grow the space to 1.5 of the needed space with existing data unchanged. More... | |
| void | reserve (size_t len, bool nocopy=false) |
| Reserve space for additional data Will grow the space to exactly what's needed. More... | |
| uint8_t * | add_unchecked (const void *data, size_t len) |
| Adds additional data without boundary checks. More... | |
| uint8_t * | add (const void *data, size_t len) |
| Adds more data WITH boundary checks; if required the buffer is resized and existing data is preserved. More... | |
| void | set (const void *data, size_t len) |
| Overwrites the existing data. More... | |
| void | clear () |
| Clears the buffer. More... | |
| void | set_mark () |
| Sets the mark; the mark can be used by the caller just like a bookmark. More... | |
| void | free () |
| Frees resources. More... | |
| uint8_t * | release (size_t *lenp=0) |
| Moves ownership of the buffer to the caller. More... | |
| void | grow (size_t new_size, bool nocopy=false) |
| Grows the buffer and copies the data unless nocopy is true. More... | |
Public Attributes | |
| uint8_t * | base |
| Pointer to the allocated memory buffer. More... | |
| uint8_t * | ptr |
| Pointer to the end of the used part of the buffer. More... | |
| uint8_t * | mark |
| A "bookmark", can be set by the caller. More... | |
| uint32_t | size |
| The size of the allocated memory buffer (base) More... | |
| bool | own |
| If true then the buffer (base) will be released when going out of scope; if false then the caller has to release it. More... | |
A dynamic, resizable and reference counted memory buffer.
Definition at line 42 of file DynamicBuffer.h.
|
inlineexplicit |
Constructor.
| initial_size | Initial size of the buffer |
| own_buffer | If true, then this object takes ownership of the buffer and releases it when going out of scope |
Definition at line 52 of file DynamicBuffer.h.
|
inline |
Destructor; releases the buffer if it "owns" it.
Definition at line 61 of file DynamicBuffer.h.
|
inline |
Adds more data WITH boundary checks; if required the buffer is resized and existing data is preserved.
| data | A pointer to the new data |
| len | The size of the new data |
Definition at line 122 of file DynamicBuffer.h.
|
inline |
Adds additional data without boundary checks.
| data | A pointer to the new data |
| len | The size of the new data |
Definition at line 106 of file DynamicBuffer.h.
|
inline |
Clears the buffer.
Definition at line 139 of file DynamicBuffer.h.
|
inline |
Returns true if the buffer is empty.
Definition at line 73 of file DynamicBuffer.h.
|
inline |
Ensure space for additional data Will grow the space to 1.5 of the needed space with existing data unchanged.
| len | Additional bytes to grow |
Definition at line 82 of file DynamicBuffer.h.
|
inline |
Returns the size of the used portion.
Definition at line 70 of file DynamicBuffer.h.
|
inline |
Frees resources.
Definition at line 150 of file DynamicBuffer.h.
|
inline |
Grows the buffer and copies the data unless nocopy is true.
| new_size | The new buffer size |
| nocopy | If true then the data will not be preserved |
Definition at line 176 of file DynamicBuffer.h.
|
inline |
Moves ownership of the buffer to the caller.
| lenp | If not null then the length of the buffer is stored |
Definition at line 162 of file DynamicBuffer.h.
|
inline |
Returns the size of the unused portion.
Definition at line 67 of file DynamicBuffer.h.
|
inline |
Reserve space for additional data Will grow the space to exactly what's needed.
Existing data is NOT preserved by default
| len | Size of the reserved space |
| nocopy | If true then the existing data is not preserved |
Definition at line 95 of file DynamicBuffer.h.
|
inline |
Overwrites the existing data.
| data | A pointer to the new data |
| len | The size of the new data |
Definition at line 132 of file DynamicBuffer.h.
|
inline |
Sets the mark; the mark can be used by the caller just like a bookmark.
Definition at line 145 of file DynamicBuffer.h.
| uint8_t* Hypertable::DynamicBuffer::base |
Pointer to the allocated memory buffer.
Definition at line 191 of file DynamicBuffer.h.
| uint8_t* Hypertable::DynamicBuffer::mark |
A "bookmark", can be set by the caller.
Definition at line 197 of file DynamicBuffer.h.
| bool Hypertable::DynamicBuffer::own |
If true then the buffer (base) will be released when going out of scope; if false then the caller has to release it.
Definition at line 204 of file DynamicBuffer.h.
| uint8_t* Hypertable::DynamicBuffer::ptr |
Pointer to the end of the used part of the buffer.
Definition at line 194 of file DynamicBuffer.h.
| uint32_t Hypertable::DynamicBuffer::size |
The size of the allocated memory buffer (base)
Definition at line 200 of file DynamicBuffer.h.
1.8.8