The Support Kit: BMemoryIO
The Be Book The Support Kit The Support Kit Index

BMemoryIO

Derived from: public BPositionIO
Declared in:  be/support/DataIO.h
Library: libbe.so
Summary:  more...


BMemoryIO represents a buffer of memory. You assign the buffer to a BMemoryIO object upon construction.


Constructor and Destructor


BMemoryIO()

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() 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.


~BMemoryIO()

virtual ~BMemoryIO()

The BMemoryIO destructor does nothing.


Member Functions


Position()  see Seek()


ReadAt()

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.


Seek() , Position()

virtual off_t Seek(off_t position, int32 mode)
virtual off_t Position(void) 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 modes:

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.


WriteAt()

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.


The Be Book The Support Kit The Support Kit Index

The Be Book,
...in lovely HTML...
for BeOS Release 5.

Copyright © 2000 Be, Inc. All rights reserved..