Microsoft KB Archive/47741

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Closing stdprn & stdaux May Not Increase Available Handles

Q47741

5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg ---------------------------------------------------------------------- The information in this article applies to: - The C Run-time (CRT), included with: - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 ---------------------------------------------------------------------- SUMMARY ======= Due to a limitation of MS-DOS, the handles stdaux and stdprn cannot be closed in order to open additional files before hitting the limit of the FILES= parameter in CONFIG.SYS. To open a file using the C run time, ALL of the following conditions must be true: 1. There must be a space in the C run-time library's internal file tables. This is normally limited to 20 files, but this limit can be increased by modifying the startup code if you're using MS-DOS 3.30 or later. 2. There must be MS-DOS file handles available to your particular process. Again, the normal limit is 20, but this can be increased with a call to function 67h of INT 21h (only under MS-DOS 3.30 or later). This can also be modified in the startup code. 3. Finally, there must be files available from MS-DOS's system-wide pool, as set by FILES= in CONFIG.SYS. (This defaults to 8, but can be set as high as 20 under MS-DOS version 3.30 and earlier or 255 under versions 3.30 and later.) MORE INFORMATION ================ The results of comparing a C program that uses the C run-time library and a MASM program that calls MS-DOS directly are shown below. Each was run with stdprn and stdaux, closed and open. C Program MASM Program --------- ------------ FILES= W/o Closing W/ Closing W/o Closing W/ Closing ------ ----------- ---------- ----------- ---------- 17 (Note 1) 14 14 14 14 18 (Note 1) 15 15 15 15 19 15 16 16 16 20 15 17 17 17 21 (Note 2) 15 17 17 17 Please note the following: 1. The formula for the number of files you can open for FILES=n, where n is less than 19, is n - 3. 2. No matter how high you set FILES=, you'll be limited to these numbers in C unless you modify the startup code as described in the README.DOC file. In MASM, you'll be limited to these numbers unless you raise the per-process limit on file handles by calling INT 21h, function 67h. 3. Running the program from a batch file doesn't change these numbers; however, reduce each number by 1 for each input or output redirection you do. 4. The MASM program doesn't get any additional handles freed up when it closes handles 3 and 4 because, contrary to what the "MS-DOS Encyclopedia" implies, MS-DOS won't allow you to reuse those two handles. Without closing handles, C programs give you a constant 15 or n - 3, whichever is smaller. The upper limit is 15 because, unless you modify the startup code, the limit is 20 minus the five default files. When you close handles 3 and 4, they are closed for C but not for MS-DOS. Therefore, you can open exactly as many handles as MS-DOS normally allows. Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00 KBCategory: kbprg KBSubcategory: CRTIss

Keywords : kb16bitonly
Issue type :
Technology : kbVCsearch kbAudDeveloper kbCRT


Last Reviewed: May 5, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.