SharedMemoryBlock Class Reference

An encapsulation of a block of memory that can be mapped by one or more (not necessarily related) processes; when one process changes the data in the block, the changes are immediately visible to the other processes. More...

#include <SharedMemoryBlock.h++>

Inheritance diagram for SharedMemoryBlock:
Inheritance graph
[legend]
Collaboration diagram for SharedMemoryBlock:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SharedMemoryBlock (const String &name, size_t size, const Permissions &perm=Permissions::USER_READ_WRITE)
 Construct a new SharedMemoryBlock.
 ~SharedMemoryBlock () throw ()
 Destructor.
void attach (bool readOnly=false) throw (SystemException)
 Attach to the memory block, creating it if it does not yet exist.
void detach () throw ()
 Detach from the memory block, and destroy it if no other process currently has it mapped.
virtual void setBase (byte_t *base) throw ()
 Overridden to have no effect.
virtual void setSize (size_t size) throw ()
 Overridden to have no effect.
String getName () const
 Get the name of the memory block.
void zero () throw ()
 Zero the memory block.
void fill (byte_t value) throw ()
 Fill the memory block with the given byte value.
byte_tgetBase () throw ()
 Get a pointer to the beginning of the memory block.
const byte_tgetBase () const throw ()
 Get a pointer to the beginning of the memory block.
size_t getSize () const throw ()
 Get the size of the memory block.
bool operator== (const MemoryBlock &other) const throw ()
 Equality operator.
bool operator!= (const MemoryBlock &other) const throw ()
 Inequality operator.
byte_t operator[] (uint_t index) const throw (OutOfBoundsException)
 Bounds-checked access.
byte_toperator[] (uint_t index) throw (OutOfBoundsException)
 Bounds-checked access.
bool copyFrom (const MemoryBlock &other) throw ()
 Copy data from another memory block to this one.
void moveFrom (MemoryBlock &other) throw ()
 Copy data from another (possibly overlapping) memory block to this one.
int indexOf (byte_t val, uint_t startIndex=0) const throw ()
 Find the first occurrence of a given byte value in the memory block, starting at a given index.
bool operator! () const throw ()
 Test if the base of the block is NULL.

Protected Attributes

byte_t_base
 A pointer to the beginning of the memory block.
size_t _size
 The size of the memory block, in bytes.

Detailed Description

An encapsulation of a block of memory that can be mapped by one or more (not necessarily related) processes; when one process changes the data in the block, the changes are immediately visible to the other processes.

Author:
Mark Lindner

Constructor & Destructor Documentation

SharedMemoryBlock ( const String name,
size_t  size,
const Permissions perm = Permissions::USER_READ_WRITE 
)

Construct a new SharedMemoryBlock.

The actual memory segment is not created and mapped until a call to attach() is made.

Parameters:
name The name of the memory block. For maximal portability, the name should consist of at most 14 alphanumeric characters and should not contain slashes.
size The size of the memory block, in bytes. This size will be rounded up to the nearest multiple of the system page size.
perm The permissions with which to create the memory block, if it does not exist at the time of the attach().
~SharedMemoryBlock (  )  throw ()

Destructor.

Detaches from the memory block.


Member Function Documentation

void attach ( bool  readOnly = false  )  throw (SystemException)

Attach to the memory block, creating it if it does not yet exist.

Parameters:
readOnly A flag indicating whether the memory block should be mapped for read-only access or read-write access.
Exceptions:
SystemException If the operation fails.
bool copyFrom ( const MemoryBlock other  )  throw () [inherited]

Copy data from another memory block to this one.

The number of bytes copied is the minimum of the sizes of the two blocks. The blocks may not overlap.

Parameters:
other The block to copy from.
Returns:
true if the copy succeeded, false if the blocks overlap.
void detach (  )  throw ()

Detach from the memory block, and destroy it if no other process currently has it mapped.

void fill ( byte_t  value  )  throw () [inherited]

Fill the memory block with the given byte value.

const byte_t* getBase (  )  const throw () [inline, inherited]

Get a pointer to the beginning of the memory block.

byte_t* getBase (  )  throw () [inline, inherited]

Get a pointer to the beginning of the memory block.

String getName (  )  const [inline]

Get the name of the memory block.

size_t getSize (  )  const throw () [inline, inherited]

Get the size of the memory block.

int indexOf ( byte_t  val,
uint_t  startIndex = 0 
) const throw () [inherited]

Find the first occurrence of a given byte value in the memory block, starting at a given index.

Parameters:
val The value to search for.
startIndex The index to begin searching at.
Returns:
The index of the first matching value, or -1 if not found.
void moveFrom ( MemoryBlock other  )  throw () [inherited]

Copy data from another (possibly overlapping) memory block to this one.

The number of bytes copied is the minimum of the sizes of the two blocks.

Parameters:
other The block to copy from. Note that the copy may result in both blocks being modified, if the source area overlaps the target area.
bool operator! (  )  const throw () [inline, inherited]

Test if the base of the block is NULL.

bool operator!= ( const MemoryBlock other  )  const throw () [inline, inherited]

Inequality operator.

bool operator== ( const MemoryBlock other  )  const throw () [inherited]

Equality operator.

byte_t & operator[] ( uint_t  index  )  throw (OutOfBoundsException) [inherited]

Bounds-checked access.

byte_t operator[] ( uint_t  index  )  const throw (OutOfBoundsException) [inherited]

Bounds-checked access.

void setBase ( byte_t base  )  throw () [virtual]

Overridden to have no effect.

Reimplemented from MemoryBlock.

void setSize ( size_t  size  )  throw () [virtual]

Overridden to have no effect.

Reimplemented from MemoryBlock.

void zero (  )  throw () [inline, inherited]

Zero the memory block.


Member Data Documentation

byte_t* _base [protected, inherited]

A pointer to the beginning of the memory block.

size_t _size [protected, inherited]

The size of the memory block, in bytes.


The documentation for this class was generated from the following files:
Generated on Fri Sep 3 23:49:37 2010 for libcommonc++ by  doxygen 1.6.3