|
| Slice () |
| Construct empty slice.
|
|
| Slice (const SharedPtr< Buffer< T > > &buffer) |
| Construct slice pointing to the whole buffer.
|
|
| Slice (Buffer< T > &buffer, size_t from, size_t to) |
| Construct slice pointing to a part of a buffer.
|
|
T * | data () const |
| Get slice data.
|
|
T * | data_end () const |
| Pointer to the next after the last element in slice.
|
|
size_t | size () const |
| Get number of elements in slice.
|
|
size_t | capacity () const |
| Get maximum possible number of elements in slice.
|
|
void | reslice (size_t from, size_t to) |
| Change slice beginning and ending inside the buffer.
|
|
T * | extend (const size_t add_sz) |
| Increase size() by add_sz .
|
|
Slice | subslice (size_t from, size_t to) const |
| Construct a slice pointing to a part of this slice.
|
|
void | print () const |
| Print slice to stderr.
|
|
T & | operator[] (const size_t i) const |
| Access to an element of the Slice with an array style.
|
|
| operator const struct unspecified_bool * () const |
| Convert to bool.
|
|
template<class T>
class roc::core::Slice< T >
Slice.
Slice<T> points to a subrange of data in Buffer<T>, where T defines the element type, e.g. uint8_t for byte buffer.
Copying a slice produces a new slice referring the same data.
Slice also acts as a kind of shared pointer to Buffer. A buffer wont be freed (returned to pool) until there are slices referring it. Copying a slice increments the buffer reference counter, and destroying a slice decrements it.
Slice has two important characteristics:
- size - the difference between the ending end beginning pointers
- capacity - the difference between the actual buffer end and the slice beginning pointers
Buffers are not resizable. They're allocated from pool and have fixed size, defined by the pool parameters.
Slices are resliceable, which means that their pointers to the buffer data may be moved withing the buffer.
The beginning pointer may be moved only forward. Once moved, it's not allowed to move it backward again. Moving it decreases the slice size and capacity. Capacity is affected because it's relative to the beginning pointer.
The ending pointer maybe freely moved forward and backward withing the slice capacity. Moving it affects the slice size, but not capacity.
In other words, slice capacity may be only decreased by moving beginning pointer, and slice size may be freely changed withing the slice capacity by moving both beginning and ending pointers.
Definition at line 54 of file slice.h.