buffer
|
 |
A dynamic memory buffer you can
use to read and write data to the heap. Use the os_buffer
class in conjunction with Streaming<ToolKit> to encode objects without the
overhead of slower hardware devices.
The os_buffer
has a default memory granularity size of 1024 bytes. Although the size is ideal
for most uses, some situations may require larger granularity for performance.
To increase the memory granularity size used by os_buffer
, use the block_size() method to specify the new
allocation unit.
Declaration
#include <ospace/io/buffer.h>
class os_buffer
Enums
enum os_buffer::
{
begin,
current,
end
};
Interface
Constructor
os_buffer()
Constructs a dynamic
memory buffer.
Destructor
~os_buffer()
Destroys this buffer and
its contents.
(os_adapter)
operator
os_adapter() const
Returns
an os_adapter for the buffer.
adjust
void
adjust( int size )
Increases the internal
storage used by the buffer size bytes.
Throws: os_io_toolkit_error
block_size
int
block_size() const
Returns the current
memory allocation block size.
block_size
void
block_size( int size )
Sets the memory
allocation block size to size .
buffer_size
int
buffer_size() const
Returns the total amount
of memory allocated by the buffer.
clear
void
clear()
Resets
the buffer state to good.
eof
bool
eof() const
Returns true
if the buffer has reached end of input.
erase
void
erase()
Clears the contents of
the buffer.
event_on_eof
bool
event_on_eof() const
Returns true
if the buffer will generate an event on EOF.
event_on_eof
void
event_on_eof( bool flag )
If flag
is true , buffer will generate an event on EOF.
expand_to
void
expand_to( int size )
Expands the total
internal storage of the buffer to size .
Throws: os_io_toolkit_error
good
bool
good() const
Returns
true if the buffer is in a good state and not
at EOF.
left
int
left() const
Returns the amount of
unused memory remaining in the buffer (the same as buffer_size()
- size() ).
ok
bool
ok() const
Returns
true if the buffer is in a good state.
read
ssize_t
read( void* buffer ,
size_t bytes )
Reads up to the specified number of bytes
of data into buffer and returns the number
of bytes read.
Throws: os_io_toolkit_error
rewind
void
rewind()
Sets
the read pointer to the beginning of the buffer.
seek
void
seek( os_off_t offset ,
int seekdir )
Seeks
to offset bytes from seekdir
(default os_buffer::begin ). If successful,
clears the buffer state.
Throws: os_file_toolkit_error
size
int
size() const
Returns the amount of
data stored by the buffer.
start
void*
start()
Returns a pointer to the
start of the buffer's internal storage. This pointer may not be valid after
subsequent operations on the buffer.
start
const
void* start() const
Returns a constant
pointer to the start of the buffer's internal storage. This pointer may not
be valid after subsequent operations on the buffer.
tell
os_off_t
tell() const
Returns the read/write
pointer offset, in bytes, from the buffer's beginning.
write
ssize_t
write( const void* buffer ,
size_t bytes )
Writes up to
the specified number of bytes of data from buffer to the buffer and returns the number
of bytes written.
Throws: os_io_toolkit_error
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.