Difference between revisions of "Bulk file I/O with OSGBPB"
(update) |
(update) |
||
Line 2: | Line 2: | ||
[[OSGBPB]] lets you read or write blocks of data from or to an open file. | [[OSGBPB]] lets you read or write blocks of data from or to an open file. | ||
Using OSGBPB makes program code more compact than using <code>'''BGET'''</code> | Using OSGBPB makes program code more compact than using <code>'''BGET'''</code> | ||
− | and <code>'''BPUT<code>''', and can also can make data transfer a lot faster | + | and <code>'''BPUT</code>''', and can also can make data transfer a lot faster |
- particularly on an unbuffered network filing system. It can also be faster | - particularly on an unbuffered network filing system. It can also be faster | ||
on disk as disk files are buffered to 256 bytes and this is not necessarily | on disk as disk files are buffered to 256 bytes and this is not necessarily | ||
Line 34: | Line 34: | ||
===Sample code=== | ===Sample code=== | ||
The following code snippet will copy all the data from <code>'''in%'''</code> to | The following code snippet will copy all the data from <code>'''in%'''</code> to | ||
− | <code>'''out%'''</code> using a buffer in memory at <code>'''data%<code>'''. | + | <code>'''out%'''</code> using a buffer in memory at <code>'''data%</code>'''. |
REM max%=maximum buffer size at data% | REM max%=maximum buffer size at data% | ||
Line 45: | Line 45: | ||
It can be made more efficient by not repeatedly reading <code>'''PTR'''</code> | It can be made more efficient by not repeatedly reading <code>'''PTR'''</code> | ||
− | and <code>'''EXT<code>'''. It is faster to access variables than it is to make | + | and <code>'''EXT</code>'''. It is faster to access variables than it is to make |
filing system calls, especially for values that don't change. | filing system calls, especially for values that don't change. | ||
Line 61: | Line 61: | ||
* [[OSGBPB]] | * [[OSGBPB]] | ||
− | [[User:WikiSysop|WikiSysop]] ([[User talk:WikiSysop|talk]]) 13: | + | [[User:WikiSysop|WikiSysop]] ([[User talk:WikiSysop|talk]]) 13:17, 8 March 2015 (UTC) |
Revision as of 14:17, 8 March 2015
OSGBPB lets you read or write blocks of data from or to an open file.
Using OSGBPB makes program code more compact than using BGET
and BPUT
, and can also can make data transfer a lot faster
- particularly on an unbuffered network filing system. It can also be faster
on disk as disk files are buffered to 256 bytes and this is not necessarily
the number you want. The following procedure is from the
FileIO library.
DEFPROCgbpb(A%,chn%,addr%,num%,ptr%) ?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:CALL &FFD1:ENDPROC
A global control block needs to be set up beforehand with X%
and Y%
pointing to it with:
DIM ctrl% 31:X%=ctrl%:Y%=X%DIV256
The procedure is called as
PROCgbpb(action, handle, address, number, pointer)
The action parameter is one of the following:
- 1 - Write bytes to file using the supplied pointer
- 2 - Write bytes to file at the current PTR
- 3 - Read bytes from file using the supplied pointer
- 4 - Read bytes from file at the current PTR
You can check whether you went past the end of the file by checking
X%!5
after the call. This contains the number of bytes
which were not transfered. This will be non-zero if you went outside the
file.
Sample code
The following code snippet will copy all the data from in%
to
out%
using a buffer in memory at data%
.
REM max%=maximum buffer size at data% REPEAT len%=max% IF PTR#in%+len%>EXT#in% THEN len%=EXT#in%-PTR#in% PROCgbpb(4,in%, data%,len%,0) PROCgbpb(2,out%,data%,len%,0) UNTIL PTR#in%>=EXT#in%
It can be made more efficient by not repeatedly reading PTR
and EXT
. It is faster to access variables than it is to make
filing system calls, especially for values that don't change.
REM max%=maximum buffer size at data% num%=EXT#in%-PTR#in% REPEAT len%=max% IF num%<len% THEN len%=num% PROCgbpb(4,in%, data%,len%,0) PROCgbpb(2,out%,data%,len%,0) num%=num%-len% UNTIL num%<0