Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CP_HandleBlock Class Reference

Memory allocation class based on Handles. More...

List of all members.

Public Member Functions

Constructor / Destructor
 CP_HandleBlock ()
 Constructor.
 CP_HandleBlock (UInt32 inSize)
 CP_HandleBlock (Handle inMacHandle, bool inOwnsHandle=true)
 CP_HandleBlock (const CP_HandleBlock &inHandleBlock)
 ~CP_HandleBlock () throw ()
 Destructor.
Copying
void CopyTo (void *ioBuffer, UInt32 inNumBytes) const
void CopyFrom (const void *inBuffer, UInt32 inNumBytes)
Getters
OSHandle GetOSHandle () const
char * GetPtr () const
Length
UInt32 Length () const
void SetLength (UInt32 inLength)
Locking
void Lock () const
void Unlock () const
bool IsLocked () const
Operators
CP_HandleBlockoperator= (const CP_HandleBlock &inHandleBlock)
 operator Handle () const
Testers
bool IsValid () const
bool OwnsHandle () const
Utility
void Wrap (OSHandle inExistingHandle, bool inOwnsHandle=true)
void Detach ()
CP_HandleBlockClone ()

Protected Attributes

OSHandle fBlock
bool fOwnsHandle
bool fLocked
UInt32 fActualBlockLength
char * fBlockPtr

Private Member Functions

Allocation
void Allocate (UInt32 inSize)
void Deallocate ()


Detailed Description

An object to manage blocks of memory using handles (i.e. relocatable memory blocks). Note: if handle based memory allocation is not support on the platforms OS, then regular pointer allocation is used.


Constructor & Destructor Documentation

CPLAT_Begin_Namespace_CPLAT CP_HandleBlock::CP_HandleBlock  ) 
 

Constructor.

Exceptions:
none 

CP_HandleBlock::CP_HandleBlock UInt32  inSize  ) 
 

Constructor.

Parameters:
inSize The size of the desired memory allocation in bytes.
Exceptions:
none 

CP_HandleBlock::CP_HandleBlock Handle  inMacHandle,
bool  inOwnsHandle = true
 

Constructor.

Parameters:
inMacHandle An existing MacOS Handle to assign to this object.
inOwnsHandle Flag to indicate if this class becomes responsible for the deletion of the OSHandle.
Exceptions:
none 

CP_HandleBlock::CP_HandleBlock const CP_HandleBlock inHandleBlock  )  [explicit]
 

Copy constructor. Ownership of the memory block will be handled according to the inOwnershipOptions parameter.

Parameters:
inHandleBlock The object to copy.
Exceptions:
none 

CP_HandleBlock::~CP_HandleBlock  )  throw ()
 

Destructor.

Exceptions:
none 


Member Function Documentation

void CP_HandleBlock::CopyTo void *  ioBuffer,
UInt32  inNumBytes
const
 

Copies the passed in number of bytes of this memory block to the passed in destination buffer. The copy will start at the beginning of the memory block.

Parameters:
ioBuffer Points to the location the bytes will be copied to.
inNumBytes The number of bytes to copy.
Exceptions:
none 
Returns:
void

void CP_HandleBlock::CopyFrom const void *  inBuffer,
UInt32  inNumBytes
 

Copies the passed in number of bytes from the passed in buffer to this block of memory, starting at the first byte of this memory block.

Parameters:
inBuffer Points to the location of the bytes to copy from.
inNumBytes The number of bytes to copy.
Exceptions:
none 
Returns:
void

OSHandle CP_HandleBlock::GetOSHandle  )  const
 

Returns the OSHandle for the memory block of this object. If this object still owns this memory, be careful not to delete the OSHandle, otherwise there will be a problem when this object tries to release the already released memory.

Exceptions:
none 
Returns:
OSHandle The OSHandle for the memory of this object.

char * CP_HandleBlock::GetPtr  )  const
 

Returns a char * to the actual bytes of this memory. This will lock the handle for accessing, in case the underlying OS can move a handle. You are responsible for calling the Unlock() memory when done to unlock the memory.

Exceptions:
none 
Returns:
char * Points to the first byte in the memory block.

UInt32 CP_HandleBlock::Length  )  const
 

Returns the length of this memory block.

Exceptions:
OSErr OSErr if there is a problem getting length.
Returns:
The length of the memory block

void CP_HandleBlock::SetLength UInt32  inLength  ) 
 

Set the length of the memory block. This will cause the platforms memory block to be resized to accommodate these changes.

Parameters:
inLength The length to resize this memory block to.
Exceptions:
OSErr OSError if setting length failed.
Returns:
void

void CP_HandleBlock::Lock  )  const
 

Locks the platforms OSHandle.

Exceptions:
none 
Returns:
void

void CP_HandleBlock::Unlock  )  const
 

Unlocks the platforms OSHandle.

Exceptions:
none 
Returns:
void

bool CP_HandleBlock::IsLocked  )  const
 

Returns true if the memory block is locked.

Exceptions:
none 
Returns:
bool Returns true if the memory block is locked.

CP_HandleBlock & CP_HandleBlock::operator= const CP_HandleBlock inHandleBlock  ) 
 

Assignment operator. This will cause the memory of the source block to be copied into a new block.

Exceptions:
none 
Returns:
void

CP_HandleBlock::operator Handle  )  const
 

Returns the MacOS Handle.

Exceptions:
none 
Returns:
OSHandle

bool CP_HandleBlock::IsValid  )  const
 

Returns true if the memory block is not NULL.

Exceptions:
none 
Returns:
bool Returns true if the memory block is not NULL.

bool CP_HandleBlock::OwnsHandle  )  const
 

Returns true if this object owns the block of memory, and is therefore responsible for its deletion. Otherwise the memory block held by this object will not be deleted by this class.

Exceptions:
none 
Returns:
bool Returns true if this object owns the memory handle.

void CP_HandleBlock::Wrap OSHandle  inExistingHandle,
bool  inOwnsHandle = true
 

Wrap ourselves around an existing platforms OSHandle. If inOwnsHandle is true, then this object takes over ownership of the OSHandle and will be responsible for deleting the memory.

Parameters:
inExistingHandle The existing OSHandle to take ownership of.
inOwnsHandle Flag to indicate if this class takes on ownership of the handle, and will be responsible for its deletion.
Exceptions:
none 
Returns:
void

void CP_HandleBlock::Detach  ) 
 

Notifies this class that it no longer owns the memory, and will not delete it. You are now responsible for deleting the memory to avoid a memory leak.

Exceptions:
none 
Returns:
void

CP_HandleBlock * CP_HandleBlock::Clone  ) 
 

Return a new CP_HandleBlock object that is a duplicate of this one. Use this method if you want to duplicate the data inside another CP_HandleBlock object without retaining a reference to it.

Exceptions:
none 
Returns:
CP_HandleBlock * The new object that is a clone of this one.

void CP_HandleBlock::Allocate UInt32  inSize  )  [private]
 

Private routine to handle the allocation of the platforms memory block.

Parameters:
inSize The desired size of the memory allocation.
Exceptions:
NULL NULL exception if the memory can't be allocated.
Returns:
void

void CP_HandleBlock::Deallocate  )  [private]
 

Private routine to handle the deallocation of the platforms memory block. This will only happen if this object owns the allocated memory, otherwise you are responsible for the deallocation of the memory.

Exceptions:
none 
Returns:
void


Member Data Documentation

OSHandle CP_HandleBlock::fBlock [protected]
 

bool CP_HandleBlock::fOwnsHandle [protected]
 

Platforms memory object.

bool CP_HandleBlock::fLocked [mutable, protected]
 

Flag to indicate who is responsible for deleting the platforms memory.

UInt32 CP_HandleBlock::fActualBlockLength [protected]
 

Flag to indicate if the block is locked.

char* CP_HandleBlock::fBlockPtr [mutable, protected]
 

Length of the memory block.


The documentation for this class was generated from the following files:
Generated on Tue Sep 20 20:21:48 2005 for CPLAT_MacOS by  doxygen 1.4.0