Inheritance diagram for BMallocIO:

Public Member Functions | |
| BMallocIO () | |
| Create a new memory buffer with block size 256. | |
| const void * | Buffer () const |
| Return a pointer to the internal buffer. | |
| size_t | BufferLength () const |
| Return the number of bytes in the buffer. | |
| virtual status_t | GetSize (off_t *size) const |
| Get the size of the object or data. | |
| virtual off_t | Position () const |
| Return the position of the cursor. | |
| virtual ssize_t | Read (void *buffer, size_t size) |
| Read data from current position. | |
| virtual ssize_t | ReadAt (off_t position, void *buffer, size_t size) |
| Read data at a certain position. | |
| virtual off_t | Seek (off_t position, uint32 seekMode) |
| Move the cursor to a given position. | |
| void | SetBlockSize (size_t blockSize) |
| Change the block size to a certain value. | |
| virtual status_t | SetSize (off_t size) |
| Change the size of the buffer. | |
| virtual ssize_t | Write (const void *buffer, size_t size) |
| Write data to the current position. | |
| virtual ssize_t | WriteAt (off_t position, const void *buffer, size_t size) |
| Write data to a certain position. | |
| virtual | ~BMallocIO () |
| Destroy the object and free the internal buffer. | |
This class creates a memory buffer and provides a BPositionIO interface to work on it. The memory buffer grows and shrinks automatically. This is especially useful if you want to use a method or function that works on an object derived from BPositionIO and you want to do something with the resulting data, or it could be useful if you want to read and write to memory in a safe way, since this class has boundary checking.
BMallocIO allocates a buffer based on a certain blocksize. This provides a mechanism that will prevent it from needing to allocate new memory too often. The default blocksize is 256 bytes, you can change it with SetBlockSize(). If you are sure you are going to use a bigger buffer, change the blocksize so that you won't have to allocate more memory too often, especially if you use this class in performance-critical code.
If you require a BPositionIO derived object that works on buffers you provide, have a look at BMemoryIO.
| BMallocIO::BMallocIO | ( | ) |
| const void * BMallocIO::Buffer | ( | ) | const |
Return a pointer to the internal buffer.
As with any pointer to internal buffers the Haiku API exposes, make sure you don't change anything since it doesn't belong to you.
| size_t BMallocIO::BufferLength | ( | ) | const |
Return the number of bytes in the buffer.
This number doesn't have to be the same size as the buffer is. Because memory is allocated in blocks the actual size of the buffer may be greater, but this method only returns the number of bytes that are actually used.
| status_t BPositionIO::GetSize | ( | off_t * | size | ) | const [virtual, inherited] |
Get the size of the object or data.
The default implementation uses Seek() with the SEEK_END flag to determine the size of the buffer. If your data or object has a different way of determining size, reimplement this method.
Please check that NULL is not passed into size if you reimplement it in your class.
| [out] | size | The size of the object is put into this parameter. |
B_OK on success or an error code on error. | ssize_t BPositionIO::Read | ( | void * | buffer, | |
| size_t | size | |||
| ) | [virtual, inherited] |
Read data from current position.
This method is derived from BDataIO. The default implementation reads data from the current position of the cursor, pointed at by Position(). If you require different behaviour, please look at BDataIO::Read() for what is expected of this method.
Implements BDataIO.
| ssize_t BMallocIO::ReadAt | ( | off_t | pos, | |
| void * | buffer, | |||
| size_t | size | |||
| ) | [virtual] |
Read data at a certain position.
| [in] | pos | Offset into the data where to read from. |
| [out] | buffer | The buffer to copy the read bytes in. |
| [in] | size | Size of the buffer. |
B_BAD_VALUE if the provided buffer is invalid. Implements BPositionIO.
| off_t BMallocIO::Seek | ( | off_t | position, | |
| uint32 | seekMode | |||
| ) | [virtual] |
Move the cursor to a given position.
| position | The position to move the cursor to. | |
| seekMode | The mode determines where the cursor is placed. Possibilities:
|
Implements BPositionIO.
| void BMallocIO::SetBlockSize | ( | size_t | blockSize | ) |
Change the block size to a certain value.
This class allocates memory in blocks. If you are in performance-critical code you might want to tweak this setting to create a better performance in case you know you are going to allocate more than the default blocksize of 256.
| blockSize | The new block size. |
| status_t BMallocIO::SetSize | ( | off_t | size | ) | [virtual] |
Change the size of the buffer.
This method changes the size of the current buffer. If size is smaller than the current size, the data will be cleared.
| size | The new size of the buffer. |
| B_OK | Resizing the data succeeded. | |
| B_NO_MEMORY | Failed to allocate the necessary memory. |
Reimplemented from BPositionIO.
| ssize_t BPositionIO::Write | ( | const void * | buffer, | |
| size_t | size | |||
| ) | [virtual, inherited] |
Write data to the current position.
This method is derived from BDataIO. The default implementation writes data to the current position of the cursor, pointed at by Position(). If you require different behaviour, please look at BDataIO::Write() for what is expected of this method.
Implements BDataIO.
| ssize_t BMallocIO::WriteAt | ( | off_t | pos, | |
| const void * | buffer, | |||
| size_t | size | |||
| ) | [virtual] |
Write data to a certain position.
| pos | Offset into the data where to write to. | |
| buffer | The buffer to copy from. | |
| size | The size of the buffer. |
B_BAD_VALUE if the provided. buffer is invalid. Implements BPositionIO.