exceeding_20the_20limit_20of_208_20open_20files
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| exceeding_20the_20limit_20of_208_20open_20files [2018/03/31 13:19] – external edit 127.0.0.1 | exceeding_20the_20limit_20of_208_20open_20files [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| //by Richard Russell, October 2015//\\ \\ Normally only a maximum of eight files may be open simultaneously in //BBC BASIC for Windows//; an attempt to open a ninth file will result in the **Too many open files** error (ERR = 192). It is possible to work around this limitation by opening-and-closing the file for each transaction (so that only one file is open at a time), for example to write a record to a file one might do:\\ | //by Richard Russell, October 2015//\\ \\ Normally only a maximum of eight files may be open simultaneously in //BBC BASIC for Windows//; an attempt to open a ninth file will result in the **Too many open files** error (ERR = 192). It is possible to work around this limitation by opening-and-closing the file for each transaction (so that only one file is open at a time), for example to write a record to a file one might do:\\ | ||
| + | <code bb4w> | ||
| file% = OPENUP(file$) | file% = OPENUP(file$) | ||
| PTR#file% = EXT#file% | PTR#file% = EXT#file% | ||
| PRINT #file$, record$ | PRINT #file$, record$ | ||
| CLOSE #file% | CLOSE #file% | ||
| + | </ | ||
| However this approach has a number of shortcomings: | However this approach has a number of shortcomings: | ||
| + | <code bb4w> | ||
| NoOfFiles% = 12 | NoOfFiles% = 12 | ||
| DIM Chan%(NoOfFiles%) | DIM Chan%(NoOfFiles%) | ||
| Line 63: | Line 66: | ||
| END | END | ||
| + | </ | ||
| Note that if this technique is used the CLOSE #0 statement (which normally closes all open files) will close only the first eight.\\ \\ Here are the replacement functions which allow this magic to happen: | Note that if this technique is used the CLOSE #0 statement (which normally closes all open files) will close only the first eight.\\ \\ Here are the replacement functions which allow this magic to happen: | ||
| + | <code bb4w> | ||
| DEF FNopenin(F$) | DEF FNopenin(F$) | ||
| LOCAL E%,F%,H% | LOCAL E%,F%,H% | ||
| Line 84: | Line 89: | ||
| IF H% SWAP H%,!500 : SWAP E%,!532 : IF H% F% = H% | IF H% SWAP H%,!500 : SWAP E%,!532 : IF H% F% = H% | ||
| = F% | = F% | ||
| + | </ | ||
| Please note that only the first eight files will be buffered by BASIC, so files in excess of that number may be accessed a little more slowly.\\ \\ Please also be aware that the value returned by these replacement functions, for files in excess of the initial eight, is the native Windows file handle. For this to work the Windows file handle must exceed 16, otherwise BB4W will mistake it for a BASIC file channel number. This is normally reliable but there is **nothing in the Microsoft API documentation which states that a file handle will always be greater than 16**. | Please note that only the first eight files will be buffered by BASIC, so files in excess of that number may be accessed a little more slowly.\\ \\ Please also be aware that the value returned by these replacement functions, for files in excess of the initial eight, is the native Windows file handle. For this to work the Windows file handle must exceed 16, otherwise BB4W will mistake it for a BASIC file channel number. This is normally reliable but there is **nothing in the Microsoft API documentation which states that a file handle will always be greater than 16**. | ||
exceeding_20the_20limit_20of_208_20open_20files.1522502359.txt.gz · Last modified: 2024/01/05 00:17 (external edit)