#include <include/hiker/prv/support/SharedBuffer.h>
A class for managing raw blocks of memory, which also includes support for sharing among multiple users with copy-on-write semantics.
To correctly use the class, you will usually keep a const SharedBuffer* to your buffer, and call Edit() when you would like to modify its data. This ensures you follow the correct copy-on-write semantics, not allowing you to modify a buffer if it has more than one user.
Public Types | |
typedef void(* | inc_ref_func )() |
typedef void(* | dec_ref_func )() |
Public Member Functions | |
const void * | Data () const |
Return a read-only version of the buffer's data. | |
void * | Data () |
Return a read/write version of the buffer's data. | |
size_t | Length () const |
Return the number of bytes in this buffer. | |
void | IncUsers () const |
Add a user to the buffer. | |
void | DecUsers () const |
Remove a user from the buffer. | |
int32_t | Users () const |
Return the number of users this buffer has. | |
SharedBuffer * | Edit (size_t newLength) const |
Given a read-only buffer, start modifying it. | |
SharedBuffer * | Edit () const |
Edit() without changing size. | |
const SharedBuffer * | Pool () const |
Place the shared buffer into the process's buffer pool. | |
int32_t | Compare (const SharedBuffer *other) const |
Perform a comparison of the data in two buffers. | |
SharedBuffer * | BeginBuffering () |
Convert this SharedBuffer to buffering mode. | |
SharedBuffer * | EndBuffering () |
Stop buffering mode started with BeginBuffering(). | |
bool | Buffering () const |
Is BeginBuffering() mode active? | |
size_t | BufferSize () const |
How big is the actual size of the buffer? | |
void | IncStrong (const void *) const |
Synonym for IncUsers(), for compatibility with sptr<>. | |
void | DecStrong (const void *) const |
Synonym for DecUsers(), for compatibility with sptr<>. | |
void | IncStrongFast () const |
Synonym for IncUsers(), for compatibility with sptr<>. | |
void | DecStrongFast () const |
Synonym for DecUsers(), for compatibility with sptr<>. | |
Static Public Member Functions | |
static SharedBuffer * | Alloc (size_t length) |
Create a new buffer of the given size. | |
static const SharedBuffer * | BufferFromData (const void *data) |
Inverse of Data(). |
|
|
|
|
|
Create a new buffer of the given size. A buffer starts out with a user count of 1; call DecUsers() to free it. |
|
Convert this SharedBuffer to buffering mode. Buffering mode is more efficient for a serious of operations that will increase or decrease the size of the buffer each time. Call EndBuffering() when done. |
|
Inverse of Data(). Given a data pointer returned by Data(), returns the SharedBuffer that the pointer came from. This exists largely for the use of String, which likes to store just the pointer to its string data. In general, it's better to store a pointer to the SharedBuffer, and use Data() to access its data. |
|
Is BeginBuffering() mode active?
|
|
How big is the actual size of the buffer?
|
|
Perform a comparison of the data in two buffers.
|
|
Return a read/write version of the buffer's data.
|
|
Return a read-only version of the buffer's data.
|
|
Synonym for DecUsers(), for compatibility with sptr<>.
|
|
Synonym for DecUsers(), for compatibility with sptr<>.
|
|
Remove a user from the buffer. If you are the last user, the buffer is deallocated. |
|
Edit() without changing size.
|
|
Given a read-only buffer, start modifying it. If the buffer currently has multiple users, it will be copied and a new one returned to you. |
|
Stop buffering mode started with BeginBuffering().
|
|
Synonym for IncUsers(), for compatibility with sptr<>.
|
|
Synonym for IncUsers(), for compatibility with sptr<>.
|
|
Add a user to the buffer.
|
|
Return the number of bytes in this buffer.
|
|
Place the shared buffer into the process's buffer pool. If a buffer of this data doesn't already exist in the pool, this buffer is modified and placed in the pool. Otherwise, your reference on this buffer is released, a reference on the on in the pool added and that buffer returned to you. |
|
Return the number of users this buffer has.
|