BMallocIO Class Reference

#include <DataIO.h>

Inheritance diagram for BMallocIO:

BPositionIO BDataIO BMemArray List of all members.

Detailed Description

BMallocIO represents a buffer of dynamically allocated memory.

A BMallocIO object allocates the buffer when you first call Write() or WriteAt(). On subsequent calls, BMallocIO makes sure enough memory is allocated to hold all the data you intend to write, reallocating it if necessary. Memory is allocated in multiples of a block size that you can set.


Public Member Functions

 BMallocIO ()
 BMallocIO (const BMallocIO &)
virtual ~BMallocIO ()
BMallocIOoperator= (const BMallocIO &)
bool operator< (const BMallocIO &) const
bool operator<= (const BMallocIO &) const
bool operator== (const BMallocIO &) const
bool operator!= (const BMallocIO &) const
bool operator>= (const BMallocIO &) const
bool operator> (const BMallocIO &) const
virtual ssize_t ReadAt (off_t pos, void *buffer, size_t size)
virtual ssize_t WriteAt (off_t pos, const void *buffer, size_t size)
virtual off_t Seek (off_t pos, uint32 seek_mode)
virtual off_t Position () const
virtual status_t SetSize (off_t size)
void SetBlockSize (size_t blocksize)
const void * Buffer () const
size_t BufferLength () const
const char * AsString () const
int Compare (const BMallocIO &) const


Constructor & Destructor Documentation

BMallocIO  ) 
 

The BMallocIO constructor creates an empty object and sets the default block size to 256 bytes. The constructor doesn't allocate any memory; memory is allocated when you first write to the object or when you call SetSize() to set the amount of memory.

BMallocIO const BMallocIO o  ) 
 

Copy constructor.

~BMallocIO  )  [virtual]
 

The BMallocIO destructor frees all memory that was allocated by the object.


Member Function Documentation

const char * AsString  )  const
 

const void * Buffer  )  const
 

Returns:
A pointer to the memory that the BMallocIO object has allocated, or NULL if it hasn't yet had occasion to allocate any memory.

size_t BufferLength  )  const
 

Returns:
The number of data bytes in the buffer (not necessarily the full number of bytes that were allocated).

int Compare const BMallocIO  )  const
 

bool operator!= const BMallocIO  )  const [inline]
 

bool operator< const BMallocIO  )  const [inline]
 

bool operator<= const BMallocIO  )  const [inline]
 

BMallocIO & operator= const BMallocIO  ) 
 

bool operator== const BMallocIO  )  const [inline]
 

bool operator> const BMallocIO  )  const [inline]
 

bool operator>= const BMallocIO  )  const [inline]
 

off_t Position void   )  const [virtual]
 

Returns:
The current position as an offset in bytes from the beginning of allocated memory.

Implements BPositionIO.

ssize_t ReadAt off_t  pos,
void *  buffer,
size_t  size
[virtual]
 

Reads up to size bytes of data from the object and copies it into the buffer. Returns the actual number of bytes placed in the buffer. The data is read beginning at the pos offset.

This function doesn't read beyond the end of the data. If there are fewer than size of data available at the pos offset, it reads only through the last data byte and returns a smaller number than numBytes. If pos is out of range, it returns 0.

Implements BPositionIO.

off_t Seek off_t  pos,
uint32  seek_mode
[virtual]
 

Sets the position in the data buffer where the Read() and Write() functions (inherited from BPositionIO) begin reading and writing. How the pos argument is understood depends on the seek_mode flag. There are three possible modes:

  • SEEK_SET. The pos passed is an offset from the beginning of allocated memory; in other words, the current pos is set to position. For this mode, pos should be a positive value.

  • SEEK_CUR. The pos argument is an offset from the current position; the value of the argument is added to the current position.

  • SEEK_END. The pos argument is an offset from the end of the object's data (not necessarily from the end of allocated memory). Positive values seek beyond the end of the data; negative values seek backwards into the data.

Attempts to seek beyond the end of allocated memory are legal: When Write() is subsequently called, the object updates its conception of where the data ends to bring the current position within range. If necessary, enough memory will be allocated to accommodate any data added at the current position.

Returns:
The current position as an offset in bytes from the beginning of allocated memory.

Implements BPositionIO.

void SetBlockSize size_t  newsize  ) 
 

Sets the size of the memory blocks that the BMallocIO object deals with. The object allocates memory in multiples of the block size. The default is 256 bytes.

status_t SetSize off_t  size  )  [virtual]
 

Sets the size of allocated memory to size (modulo the block size). Shrinking the buffer should always be successful (B_OK); if the buffer can't be grown, B_NO_MEMORY is returned.

Reimplemented from BPositionIO.

ssize_t WriteAt off_t  pos,
const void *  buffer,
size_t  size
[virtual]
 

Copies size bytes of data from buffer into the object's data beginning at pos.

A successful WriteAt() always returns size - WriteAt() reallocates the buffer (in multiples of the block size) if it needs more room. If the reallocation fails, this function returns B_NO_MEMORY.

Implements BPositionIO.


Copyright 2005 by yellowTAB GmbH, Be Inc., Palm Source Inc. and their respective legal successors
All rights reserved.