Increasing the Maximum Number of File Handles and Streams

You can change the maximum number of file handles and streams that your program can handle. The process is simple and involves changing some constants in the startup source files, which are provided with Microsoft C/C++, and then compiling and linking the new startup code with your program. The following sections describe the process.

Increasing File Handles

DOS, Windows, and QuickWin use the value of the constant _NFILE_ to establish the maximum number of available file handles. To increase the number of file handles, edit the startup source file CRT0DAT.ASM and change the line

_NFILE_ = 20

so that _NFILE_ is set to the desired maximum. For example, to increase the maximum number of available file handles to 40, change the line as shown here:

_NFILE_ = 40

CRT0DAT.ASM contains a section of conditional code that is automatically enabled when you change the value of _NFILE_.

QuickWin uses the constant _WFILE_ to establish the maximum number of available text child windows. You can edit CRT0DAT.ASM to change _WFILE_. Change the line

_WFILE_ = 20

so that _WFILE_ is set to the desired maximum. For example, to increase the maximum number of available text child windows to 40, change the line as shown here:

_WFILE_ = 40

Note:

Increasing the number of file handles allows you to use low-level I/O functions, such as _open and _read, with more files. However, it does not affect the number of stream-level I/O files (that is, the number of FILE * streams).

Increasing Streams

To increase the maximum number of streams, edit one or more of the following source files and constants:

System Source File Constant

DOS _FILE.C _NFILE_
Windows and QuickWin FILE.ASM _NFILE_
QuickWin WFILE.ASM _WFILE_

For DOS, Windows, and QuickWin, change the line

_NFILE_ equ 20

to set _NFILE_ to the desired maximum. For example, to allow a maximum of 40 streams, change the line as shown here:

_NFILE_ equ 40

In addition, you can change the value of the constant _WFILE_, found in WFILE.ASM, to increase the maximum number of available QuickWin text child windows.

Increasing the number of streams allows you to use stream-level I/O functions, such as fopen and fread, with more files.

Note:

The number of low-level file handles must be greater than or equal to the number of stream-level files. For example, if you increase the value of _NFILE_ in the module _FILE.C, you must also increase the value of _NFILE_ in the module CRT0DAT.ASM. Similarly, if you increase the value of _WFILE_ in the module WFILE.ASM, you must also increase the value of _WFILE_ in the module CRT0DAT.ASM.

Increasing the System Limit

To use more than 20 files at a time, you must increase the file limit imposed on your process by the operating system.

To increase the system-wide limit, increase the number of files available on your system as a whole by editing your system configuration file (CONFIG.SYS). For example, to allow 50 open files at a time on your system, put this statement in the configuration file:

FILES=50

Using the Modified Startup Files

After you modify one or more of the startup source files, you need to recompile the file(s) using the batch file CSTARTUP.BAT. Be sure to read the file README.TXT, which is located in the same directory as CSTARTUP.BAT, before running the batch file.

To use a new object file, either explicitly link your program with it or replace it in the appropriate model of the run-time library. For example, after you assemble CRT0DAT.ASM, the object file will be CRT0DAT.OBJ.