| Class Overview |
BMemoryIO(void* buffer,
size_t numBytes);
BMemoryIO(const void* buffer,
size_t numBytes);
The BMemoryIO constructor assigns the object a buffer with at least
numBytes of available memory. If the buffer is declared const, the object
is read-only; calls to
Write()
(inherited from BPositionIO) and
WriteAt() will fail. Otherwise, the
buffer can be both read and written. In either case, the caller retains
responsibility for the buffer; the BMemoryIO object won't free it.
virtual ssize_t ReadAt(off_t position,
void* buffer,
size_t numBytes);
Copies up to numBytes bytes of data from the object into the buffer and
returns the actual number of bytes placed in the buffer. The data is read
beginning at the position offset.
This function doesn't read beyond the end of the data. If there are fewer
than numBytes of data available at the position offset, it reads only
through the last data byte and returns a smaller number than numBytes. If
position is out of range, it returns 0.
virtual off_t Seek(off_t position,
int32 mode);virtual off_t Position() const;
Seek() sets the position in the data buffer where the
Read() and
Write()
functions (inherited from
BPositionIO)
begin reading and writing. How the position
argument is understood depends on the mode
flag. There are three possible modes:
| Constant | Description |
|---|---|
| The |
| The |
| The |
Write()
fails if the current position is beyond the end of assigned memory.
Both Seek() and Position()
return the current position as an offset in
bytes from the beginning of allocated memory.
virtual ssize_t WriteAt(off_t position,
const void* buffer,
size_t numBytes);
Copies numBytes bytes of data from buffer
into allocated memory beginning
at position, and returns the number of bytes written.
WriteAt() won't write outside the memory buffer.
If position is beyond
the end of the buffer, it returns 0. If the object is read-only, it
returns B_NOT_ALLOWED.