Again, thank you all. Along the lines of giving as well as receiving, I here present an interesting detail.
Going around a loop, at one point in the loop reading a byte from a file; this is too slow. I would like to read in big blocks from the file, then at the end with less than 1 block left I'd read in the last few bytes as bytes. The idea is that I can read a block of say 128 bytes a lot faster than 128 individual bytes.
I could always just read a lot of big blocks, then close and reopen the file for random byte access to get the last few. But just for fun let's see if I can use "absolute" on file handles.
I will define blocks of ten characters, to see if the idea works in principle where I can use write() to see the results before I proceed with huge blocks and humongous files. See if I can read those in then whether the file is also open for character reading, if the file pointer works right...
Program experiment;
type
block = array[ 0..9 ] of char;
var
blockFile : file of block;
charFile : file of char absolute blockFile;
blockArray : array[0..4] of block;
charArray : array[0..49] of char absolute blockArray;
i : uint32;
begin
for i := 0 to 49 do
charArray[ i ] := '-';
assign( blockFile, 'sample.txt' );
reset( blockFile );
for i := 0 to 2 do
read( blockFile, blockArray[ i ] );
for i := 30 to 37 do
read( charFile, charArray[ i ] );
close( blockFile );
for i := 0 to 49 do
write( charArray[ i ] );
end.
input file:
this is a test of the absolute feature of Free Pascal. I don't know if this will work
results
this is a test of the absolute feature------------
It would appear that it really does work. Not sure why but I surmise that the file pointer is always in bytes. When I read a block, the pointer is advanced by <blocksize> bytes.