Use the mmioSetBuffer function to enable or disable I/O buffering for reading to or writing from files. You can also change the size of the internal I/O buffer (8KB default) or supply your own buffer for use as a memory file.

The mmioSetBuffer function requires a pchBuffer parameter, which identifies the pointer to a user-supplied buffer for buffered I/O. If you want mmioSetBuffer to allocate the buffer, or if you want to disable any predefined I/O buffers, set pchBuffer to NULL. A second parameter, cchBuffer, specifies the size of the caller-supplied buffer. If you set pchBuffer to NULL, cchBuffer is the size of the buffer that the you want mmioSetBuffer to allocate. To disable buffering, set pchBuffer and cchBuffer to NULL.

The following example illustrates how to open an unbuffered file named TESTING and then allocate an internal 16KB buffer.

HMMIO hFile;
.
.
.
if ((hFile = mmioOpen("TESTING", NULL, MMIO_READ)) !=NULL) {
   /* File opened successfully; request an I/O buffer */
   if (mmioSetBuffer(hFile, NULL, 16384L, 0))
       /* Buffer cannot be allocated */
   else
       /* Buffer allocated successfully */
}
else
     /* File cannot be opened */

The following example illustrates how to open a buffered file named TESTING and then disable buffered I/O.

HMMIO hmmio;
.
.
.
if ((hmmio = mmioOpen("TESTING", NULL, MMIO_ALLOCBUF)) !=NULL) {
   /* File opened successfully; disable buffered I/O */
   if (mmioSetBuffer(hFile, NULL, NULL, 0))
       /* Cannot disable buffered I/O  */
   else
       /* Buffered I/O disabled successfully */
}
else
       /* File cannot be opened */


[Back] [Next]