ILE C/C++ Programmer's Guide

Improving Performance when Using Stream Input and Output Functions

Although using ILE C record I/O functions improves performance more effectively than stream I/O functions, there are still ways to improve performance when using stream I/O.

You can use IFS stream files, with performance similar to record I/O functions, by specifying SYSIFCOPT(*IFSIO) on the CRTCMOD or CRTBNDC commands.

You should use the macro version of getc instead of fgetc() to read characters from a file. See Using Static Class Member Functions or Global Variables. The macro version of getc() reads all the characters in the buffer until the buffer is empty. At this point, getc() calls fgetc() to get the next record.

For the same reason, you should use putc() instead of fputc(). The macro version of putc() writes all the characters to the buffer until the buffer is full. At this point, putc() calls fputc() to write the record into the file.

Because stream I/O functions cause many function calls; reducing their use in your application improves performance. The following illustrates calls to printf():

Figure 46. Using printf()




printf("Enter next item.\n");
printf("When done, enter 'done'.\n");

The two calls to printf() can be combined into a single call so that one call is saved as follows:

Figure 47. Using printf() to Reduce Function Calls




printf("Enter next item.\n"
"When done, enter 'done'.\n");


[ Top of Page | Previous Page | Next Page | Table of Contents ]