A chunk is the building block for buffers. More...
#include <BufferDetail.hh>
Public Types | |
typedef boost::shared_ptr< Chunk > | SharedPtr |
Public Member Functions | |
Chunk (size_type size) | |
Default constructor, allocates a new underlying block for this chunk. | |
Chunk (const data_type *data, size_type size, const free_func &func) | |
Foreign buffer constructor, uses the supplied data for this chunk, and only for reading. | |
void | truncateFront (size_type howMuch) |
Remove readable bytes from the front of the chunk by advancing the chunk start position. | |
void | truncateBack (size_type howMuch) |
Remove readable bytes from the back of the chunk by moving the chunk cursor position. | |
data_type * | tellWritePos () const |
Tell the position the next byte may be written to. | |
const data_type * | tellReadPos () const |
Tell the position of the first byte containing valid data. | |
void | incrementCursor (size_type howMuch) |
After a write operation, increment the write position. | |
size_type | dataSize () const |
Tell how many bytes of data were written to this chunk. | |
size_type | freeSize () const |
Tell how many bytes this chunk has available to write to. | |
size_type | capacity () const |
Tell how many bytes of data this chunk can hold (used and free). | |
Friends | |
bool | operator== (const Chunk &lhs, const Chunk &rhs) |
Compare underlying buffers and return true if they are equal. | |
bool | operator!= (const Chunk &lhs, const Chunk &rhs) |
Compare underlying buffers and return true if they are unequal. |
A chunk is the building block for buffers.
A chunk is backed by a memory block, and internally it maintains information about which area of the block it may use, and the portion of this area that contains valid data. More than one chunk may share the same underlying block, but the areas should never overlap. Chunk holds a shared pointer to an array of bytes so that shared blocks are reference counted.
When a chunk is copied, the copy shares the same underlying buffer, but the copy receives its own copies of the start/cursor/end pointers, so each copy can be manipulated independently. This allows different buffers to share the same non-overlapping parts of a chunk, or even overlapping parts of a chunk if the situation arises.
avro::detail::Chunk::Chunk | ( | const data_type * | data, | |
size_type | size, | |||
const free_func & | func | |||
) | [inline] |
Foreign buffer constructor, uses the supplied data for this chunk, and only for reading.
void avro::detail::Chunk::truncateBack | ( | size_type | howMuch | ) | [inline] |
Remove readable bytes from the back of the chunk by moving the chunk cursor position.
void avro::detail::Chunk::truncateFront | ( | size_type | howMuch | ) | [inline] |
Remove readable bytes from the front of the chunk by advancing the chunk start position.