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

CP_Malloc Class Reference

A class to wrap malloc / calloc / free functions. More...

List of all members.

Public Member Functions

Constructor / Destructor
 CP_Malloc ()
 Constructor.
 CP_Malloc (UInt32 inSize)
 CP_Malloc (CP_Malloc &inPtrBlock)
 ~CP_Malloc ()
 Destructor.
Copying
void CopyTo (void *ioBuffer, UInt32 inNumBytes) const
void CopyFrom (const void *inBuffer, UInt32 inNumBytes)
Getters
char * GetPtr () const
Length
UInt32 Length () const
void SetLength (UInt32 inLength)
Operators
CP_Mallocoperator= (const CP_Malloc &inPtrBlock)
Testers
bool IsValid () const
bool OwnsPtr () const
Wrapping
void Wrap (char *inExistingPtr, bool inOwnsPtr=true)
void Detach ()

Protected Attributes

char * fBlock
bool fOwnsPtr
UInt32 fActualBlockLength

Private Member Functions

Allocation
void Allocate (UInt32 inSize)
void Deallocate ()


Detailed Description

This class allocates memory blocks using malloc, and provides for allocation in the constructorr, and deallocation in the destructor.


Constructor & Destructor Documentation

CPLAT_Begin_Namespace_CPLAT CP_Malloc::CP_Malloc  ) 
 

Constructor.

Exceptions:
none 

CP_Malloc::CP_Malloc UInt32  inSize  )  [explicit]
 

Constructor.

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

CP_Malloc::CP_Malloc CP_Malloc inPtrBlock  )  [explicit]
 

Copy constructor.

Parameters:
inPtrBlock The object to copy.
Exceptions:
none 

CP_Malloc::~CP_Malloc  ) 
 

Destructor.

Exceptions:
none 


Member Function Documentation

void CP_Malloc::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_Malloc::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

char * CP_Malloc::GetPtr  )  const
 

Returns the pointer to the memory block of this object. Will implicitely lock the block, so you'll need to call Unlock() before you can resize the block.

Exceptions:
none 
Returns:
char A char * for the memory of this object.

UInt32 CP_Malloc::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_Malloc::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:
std::bad_alloc OSError if out of memory or setting length failed because block is locked.
OSErr OSError if setting length failed for other reasons.
Returns:
void

CP_Malloc & CP_Malloc::operator= const CP_Malloc inPtrBlock  ) 
 

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

Exceptions:
none 
Returns:
void

bool CP_Malloc::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_Malloc::OwnsPtr  )  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_Malloc::Wrap char *  inExistingPtr,
bool  inOwnsPtr = true
 

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

Parameters:
inExistingPtr The existing char * to take ownership of.
inOwnsPtr 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_Malloc::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

void CP_Malloc::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_Malloc::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

char* CP_Malloc::fBlock [protected]
 

bool CP_Malloc::fOwnsPtr [protected]
 

Points to the allocated memory.

UInt32 CP_Malloc::fActualBlockLength [protected]
 

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


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