Chapter 14:
RAM File Functions
 

The RAM file functions can be used to save a chart to memory instead of a file.

 

AllocRamFile(); Allocate a RAM File

 

FreeRamFile(); Free RAM File

 

GetRamFileBuffer(); Get RAM File Buffer

 

GetRamFileName(); Get RAM File Name

 

RFgetc(); Ram File Get Character

 

RFrewind(); Ram File Rewind

 

RFseek(); Ram File Seek

 

RFwrite(); Ram File Write

 

SetRamFileSize(); Set RAM File Size

   

AllocRamFile()

 

This function allocates memory for a RamFileRec structure of the size specified by initialSize. It returns a pointer to the initialized RamFileRec.

Syntax:

RamFilePtr PUBLIC
AllocRamFile (
     MEMSIZE initialSize
);

Input:

initialSize: INT16 Value indicating the initial size of the ram file in bytes

Return:

RamFilePtr; Null = Allocation Failure, Non-Zero = Pointer to a RamFileRec

Example:

//Allocate a RamFile of zero size
pRamFile = AllocRamFile ( 0 );

Also See:

FreeRamFile(), GetRamFileBuffer(), GetRamFileName(), RFgetc(), RFrewind(), RFseek(), RFwrite(), SetRamFileSize()

FreeRamFile()

 

This function frees a RAM File memory structure previously allocated by AllocRamFile().

Syntax:

void PUBLIC
FreeRamFile (
     RamFilePtr pRamFile
);

Input:

pRamFile: Pointer to a Ram File previously allocated by AllocRamFile(). See the RamFileRec in Appendix A.

Return:

None

Example:

//Free any temporary ram files
//if we had to convert any old TDI files
if (pRamFile) {
     FreeRamFile(pRamFile);
}

Also See:

AllocRamFile()

   

GetRamFileBuffer()

 

This function gets the memory address of a RAM File previous allocated by the AllocRamFile() function.

Syntax:

LPSTR PUBLIC
GetRamFileBuffer (
     RamFilePtr pRamFile
);

Input:

pRamFile: Pointer to a Ram File previously allocated by AllocRamFile(). See the RamFileRec structure in Appendix A.

Return:

LPSTR: Pointer to the Ram File data.

Example:

/*** write buffer to the TIFF file ***/
nStatus = Tiff_WriteEntry(pOutput,
     TIFFX_FILE_3D3,
     TIFF_TYPE_ASCII,
     ulBytes,
     GetRamFileBuffer(pRamFile) );
CheckStatus(nStatus);

Also See:

AllocRamFile(), GetRamFileName()

   

GetRamFileName()

 

This function returns an ASCII coded character name for the Ram File pointed to by pRamFile.

Syntax:

LPSTR PUBLIC
GetRamFileName (
     RamFilePtr pRamFile
);

Input:

pRamFile: Pointer to a Ram File previously allocated by AllocRamFile(). See the RamFileRec structure in Appendix A.

Return:

LPSTR: Pointer to a buffer where the Ram File name is stored.

Example:

lstrcpy ( szFile,
     GetRamFileName (
     pRamFile ) );

Also See:

AllocRamFile(), GetRamFileBuffer()

   

RFgetc()

 

This function reads a single character as an unsigned integer character converted to an INT16 from the input Ram File at the current position. The function then advances the position to point at the next character.

Syntax:

INT16 PUBLIC
RFgetc (
     RamFilePtr pRamFile
);

Input:

pRamFile: Pointer to a RAM file previously allocated with AllocRamFile(). See the RamFileRec in Appendix A.

Return:

INT16: EOF if end-of-file reached. Otherwise, the INT16 value of the character at the current position in the RAM file.

Example:

/* check for RamFile */
if (iopath->isRamFile)
{

     return RFgetc(
      (RamFilePtr) iopath->pBuffer);
}

Also See:

RFrewind(), RFseek(), RFwrite()

RFrewind()

 

This function resets the current position in the RAM file to the beginning of the file.

Syntax:

void PUBLIC RFrewind (
     RamFilePtr pRamFile
);

Input:

pRamFile: Pointer to a RAM file previously allocated with AllocRamFile(). See the RamFileRec in Appendix A.

Return:

None

Example:

status = Save_TIFFGraphPath(
     &iopath,
     pGraph,
     nCloneMode,
     FILEFMT_BINARY,FALSE);
/* allocate a new graph */
pNewGraph = AllocGraphPtr();
/* load the graph object back in */
RFrewind(pRamFile);

Also See:

RFgetc(), RFseek(), RFwrite()

   

RFseek ()

 

This function is similar to the C-Library fseek() function. It seeks lBytes from nOrigin in the Ram file.

Syntax:

INT32 PUBLIC
RFseek (
     RamFilePtr pRamFile,
     INT32 lBytes,
     INT16 nOrigin
);

Input:

pRamFile: Pointer to a RAM file previously allocated with AllocRamFile(). See the RamFileRec in Appendix A.

 

lBytes: Number of bytes to seek

 

nOrigin: Starting location in Ram file

Return:

INT32: if successful, file position in bytes after operation, -1 if error.

Also See:

RFgetc(), RFrewind(), RFwrite()

RFwrite()

 

This function writes the first buflen bytes of buf to the specified Ram File at the current position.

Syntax:

INT16 PUBLIC
RFwrite (
     RamFilePtr pRamFile,
     char FAR *buf,
     MEMSIZE buflen
);

Input:

pRamFile: Pointer to a RAM file previously allocated with AllocRamFile(). See the RamFileRec in Appendix A.

 

buf: Information to be written in RAM file

 

buflen: Number of bytes to write

Return:

INT16: Zero if successful. If the function fails, EOF is returned indicating that memory allocation failed.

Example:

if (iopath->isRamFile)
{
     /* write to ram */
     if (RFwrite(
           (RamFilePtr) iopath->pBuffer,
          buf, count ) == EOF )
          count = 0;
}

Also See:

RFgetc(), RFrewind(), RFseek()

SetRamFileSize()

 

This function sets the size of a RAM file.

Syntax:

void PUBLIC SetRamFileSize (
     RamFilePtr pRamFile,
     UINT32 lBytes
);

Input:

pRamFile: Pointer to a Ram File previously allocated by AllocRamFile(). See the RamFileRec in Appendix A.

 

lBytes: Length of the RAM file in bytes.

Return:

None

Example:

/* Position disk file pointer
** read the disk data
** into the ramfile's buffer
*/
IOseek(pInput->iop,
     pEntry->data.ulLong,
     IO_SEEK_BEG);
if (ulBytes != (UINT32)
     IOread(pInput->iop,
     GetRamFileBuffer(pRamFile),
     ulBytes))
CheckStatus(nStatus = E00_FILE_READ_ERROR);
SetRamFileSize(pRamFile, ulBytes);

Also See:

AllocRamFile()