KCMS CMM Reference Manual

KcsMemoryBlock Class

The KcsMemoryBlock class is a memory-based I/O derivative of the KcsIO class. It provides a way to manipulate blocks of memory by creating a KcsIO object. You can use the protected and public member functions in this class in the implementation of your CMM; you cannot override any member function in this class.

The header file for the class is kcsmblk.h.


Note -

It is highly recommended that you do not use any of the variables and functions for handle-based memory in the kcsmblk.h header file. Handle-based memory is not required on the Solaris system.


The constant and #define identifiers for this class are defined in the kcsids.h header file as:

const KcsId KcsIOMBlkId = {(0x4D426C6BUL)}; /* 'MBlk' */
#define KcsIOMBlkIdd (0x4D426C6BUL) /* 'MBlk' */

In addition to the KcsIO virtual member functions that must be overridden for a minimal KcsIO implementation, the KcsMemoryBlock class has member functions for manipulating blocks of memory. See Table 2-4 for a list of the member functions minimally required to derive from the KcsIO class.

The enumerations and protected and public members are described.

Enumerations

The KcsMemboryBlock class provides the following enumerations.

Table 2-5 KcsMemoryBlock Enumerations

Enumeration 

Description 

enum KcsMemoryKind {
 	KCS_APPLICATION_HEAP,
 	KCS_SYSTEM_HEAP };

enum used in setCursorPos(). The object is in the application or system heap.

Protected Members

The KcsMemboryBlock class provides the following protected members

Table 2-6 KcsMemoryBlock Protected Members

Protected Member 

Description 

long allocMe;

Determines whether memory block is allocated. 

char* curPtr();

Returns the current address of the memory block + position. 

long numElements;

Number of elements if memory block is an array.

long pos;

Current position in memory block. 

long realEOF;

Number of bytes actually written to memory file. 

long size;

Number of bytes allocated to contain memory file. 

char *startPtr;

Start of char-pointer-based memory block. 

Public Members

The KcsmemoryBlock class provides the following public members.

Table 2-7 KcsMemoryBlock Public Members

Public Member 

Description 

KcsStatus
get(char* buf, long nbytes);

Gets nbytes of data starting at the current cursor position. Post-increments the cursor position by nbytes.

long getNumElements() {return numElements;}

Returns the number of elements in the KcsMemoryBlock object as a long.

long getSize();

Returns the size of the KcsMemoryBlock object.

KcsMemoryBlock(KcsStatus *status, char *start,
 	long size, long numElements = 1,
 	const unsigned long absBaseOffset = 0);

Constructor. Specifies a character pointer in start, block size in size, and number of elements in numElements.

KcsMemoryBlock(KcsStatus *status, long size,
 	long numElements = 1,
 	const unsigned long absBaseOffset = 0,
 	const KcsMemoryKind kind =
 		KCS_APPLICATION_HEAP);

Constructor. Allocates and deallocates the memory. 

virtual ~KcsMemoryBlock();

Destructor. 

long position() {return pos;}

Returns the current cursor position. 

void position(long posit) {pos=posit;}

Sets the current cursor position. 

KcsStatus
put(char* buf, long nbytes);

Puts nbytes of data into the KcsMemoryBlock object at the current cursor position. Post-increments the cursor position by nbytes.

Example

This example shows you how to change the size of memory with the KcsMemoryBlock class.


Example 2-2 Resizing Memory with KcsMemoryBlock

KcsStatus resizeIt()
 {
 	unsigned long sNewSize = 10;
 	KcsStatus sStatus;
 	KcsMemoryBlock *memBlock;
 	char * buffer = {`a','b','c','d'};

 	// create a new KcsMemoryBlock object
 	memBlock = new KcsMemoryBlock(&sStatus,4);
 	if (sStatus != KCS_SUCCESS)
 			return (sStatus);
 	// put the four bytes above into the new KcsMemoryBlock
 	sStatus = memBlock->put(buffer,4);
 	if (sStatus != KCS_SUCCESS)
 			return (sStatus);
 	// resize the KcsMemoryBlock from 4 to 10	
 	sStatus = memBlock->reSize(sNewSize);
 	//Finished with the data
 	delete memBlock;
 	return (sStatus);
 }