Class: TChunkyMemory

Declaration: Memory.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

MCollectible

Inherited By:

THeapChunkyMemory

Purpose:

TChunkyMemory is an abstract base class that specifies a protocol for managing memory as a sequence of discontiguous chunks. The protocol allows the user of a TChunkyMemory to view the memory as a sequence of bytes.

Instantiation:

Allocate on the heap or the stack.

Deriving Classes:

Derived classes of this abstract class override its pure virtual member functions to implement the defined protocol. This is done by the classes THeapChunkyMemory and TVMChunkyMemory. The primary reason one might define a new derived class is to implement a different chunk allocation scheme.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Member Function: TChunkyMemory::~TChunkyMemory

virtual ~ TChunkyMemory ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Derived classes of TChunkyMemory should release all of the memory allocated they have allocated in their destructors.

Member Function: TChunkyMemory::operator<<=

virtual TStream & operator <<= (TStream & fromWhere)

Interface Category:

API.

Purpose:

Stream-in operator.

Calling Context:

Called to stream in data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself in from.

Exceptions:

Derived classes should throw a TInvalidVersionError if the object read in from the stream has an invalid version number.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::operator>>=

virtual TStream & operator >>=(TStream & toWhere) const

Interface Category:

API.

Purpose:

Stream-out operator.

Calling Context:

Called to stream out data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself out to.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Derived classes of TChunkyMemory should implement this operator to stream out the entire contents of the chunky memory. This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::SetChunkSize

virtual void SetChunkSize (size_t chunkSize)

Interface Category:

API.

Purpose:

Sets the size of chunk to allocate when more memory is requested.

Calling Context:

Called to change the size of chunk allocated by the TChunkyMemory.

Parameters:

Return Value:

None.

Exceptions:

Derived classes should throw a TGeneralKernelException(kBadArgument) if an invalid chunk size is passed.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::GetChunkSize

virtual size_t GetChunkSize () const

Interface Category:

API.

Purpose:

Returns the size of chunk to allocate when more memory is requested.

Calling Context:

Called to determine information about how the TChunkyMemory object allocates new chunks.

Parameters:

Return Value:

A size_t that indicates the size of chunk that is allocated when AllocateMemoryChunk is called.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::GetDefaultChunkSize

virtual size_t GetDefaultChunkSize () const

Interface Category:

API.

Purpose:

Returns the size of chunk to allocate when more memory is requested if a chunk size has not been specified.

Calling Context:

Called to determine information about how the TChunkyMemory object allocates new chunks.

Parameters:

Return Value:

A size_t that indicates the size of chunk that is allocated when AllocateMemoryChunk is called if a different chunk size has not been set by calling the SetChunkSize member function.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::GetTotalSize

virtual size_t GetTotalSize () const

Interface Category:

API.

Purpose:

Returns the length of the chunky memory in bytes.

Calling Context:

Called to query the state of the TChunkyMemory object.

Parameters:

Return Value:

A size_t that is the length of the chunky memory in bytes.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::LocateChunk

virtual void LocateChunk (size_t where, TMemorySurrogate & theContainingRange, size_t & offset)

Interface Category:

API.

Purpose:

Returns a TMemorySurrogate that describes the chunk that contains a specified offset.

Calling Context:

Called to query the state of the TChunkyMemory object or in preparation to access the memory that comprises the chunky memory.

Parameters:

Return Value:

None.

Exceptions:

Derived classes should throw a TGeneralKernelException(kBadArgument) if where is beyond the end of the chunky memory.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::CutBackTo

virtual void CutBackTo (size_t numberOfBytes)

Interface Category:

API.

Purpose:

Truncates the length of the chunky memory to the size passed.

Calling Context:

Called to modify the state of the TChunkyMemory.

Parameters:

Return Value:

None.

Exceptions:

Derived classes should throw a TGeneralKernelException(kBadArgument) if numberOfBytes is beyond the current end of the chunky memory.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::AllocateMemoryChunk

virtual void AllocateMemoryChunk (TMemorySurrogate & theAllocatedRange)

Interface Category:

API.

Purpose:

Allocates a new chunk of memory and appends it to the chunky memory.

Calling Context:

Called when the chunky memory needs to be extended.

Parameters:

Return Value:

None.

Exceptions:

Derived classes should throw a TGeneralKernelException(kInsufficientMemory) if there is not enough memory to allocate another chunk.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.

Member Function: TChunkyMemory::TChunkyMemory

  1. TChunkyMemory ()
  2. TChunkyMemory (const TChunkyMemory & aChunkyMemory)

Interface Category:

API.

Purpose:

  1. Default constructor.
  2. Copy constructor.

Calling Context:

  1. Called by the stream-in operators.
  2. Called to copy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TChunkyMemory::operator=

TChunkyMemory & operator =(const TChunkyMemory & theChunkyMemory)

Interface Category:

API.

Purpose:

Assignment operator.

Calling Context:

Called when an object is assigned to another compatible object.

Parameters:

Return Value:

A non-const reference to the left-hand side object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TChunkyMemory::GetChunkCollection

virtual void GetChunkCollection (TCollectionOf < TMemorySurrogate > & theCollection)

Interface Category:

API.

Purpose:

Appends, in order, TMemorySurrogates describing each chunk in the chunky memory to the collection passed in.

Calling Context:

Called to query the state of the TChunkyMemory object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function. Derived classes of TChunkyMemory should not call this operator.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.