[color #000080]IF[/color] bufferedFileBufferOffset% [color #000080]THEN[/color]
usedBuffer$ = [color #000080]LEFT$[/color](bufferedFileBuffer$, bufferedFileBufferOffset%)
[color #000080]PUT[/color] #bufferedFileNumber%, , usedBuffer$
bufferedFileBufferOffset% = 0
[color #000080]END IF
END SUB[/color]
[/tt]
To start using these [tt][color #000080]SUB[/color][/tt]s, call [tt][color #000080]SUB[/color] selectFileToBuffer[/tt] and pass it a file number opened by [tt][color #000080]OPEN[/color][/tt] in [tt][color #000080]BINARY[/color][/tt] mode, as well as a buffer size (4096 or 8192 should be about optimal -- smaller buffers cause degraded performance, but QB has trouble with strings larger than 8 kilobytes (it can do them, but the string space gets all fragmented and messy)).
Then, to output bytes or strings, call the appropriate output function (the routines remember the file number automatically). When you are done, call [tt][color #000080]SUB[/color] flushBuffer[/tt] before closing your file, otherwise some data will not be written to file and will be lost.
You can switch from your own output to this buffered output at any time (provided the file was opened [tt][color #000080]FOR BINARY[/color][/tt]), and you can switch back to your own output code at any time by calling [tt][color #000080]SUB[/color] flushBuffer[/tt], however doing so very often would reduce the effectiveness of the buffer and degrade performance. When switching back from your routines to the buffered routines after the buffered routines have already been in use, you do not need to call [tt][color #000080]SUB[/color] selectFileToBuffer[/tt] again, as all the settings are remembered and the buffer is in a proper state from [tt][color #000080]SUB[/color] flushBuffer[/tt]. It should also be safe to switch the buffer from one file to another (it automatically flushes the buffer), but the same performance issue applies.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.