This may be useful. I recently had to learn how to read a file to store the contents into main memory. In my program I check whether the bytes are numeric data before converting to BCD and storing to memory.

Reading a file byte by byte
// Read file

while( fileio.eof( inpH ) = false ) do
// Read and store the next char from the file:

fileio.getc( inpH);
if (al in '0'..'9') then
dec(esi); and (15, al); mov (al, [esi]);
endif;

endwhile;


Reading a file line by line
// Read file

while( fileio.eof( inpH ) = false ) do
// Read line into string
fileio.gets(inpH, s);
mov (s, esi);
// get and store the next char :
wex:
mov([esi],al);
if (al in '0'..'9') then
dec(edi); and (15, al); mov (al, [edi]); inc (esi); jmp wex;
endif;

endwhile;


The second version was three or four times faster...

Before the loop I reserve space for the string (each line is a maximum 70 characters) and after the loop I free the space.
     stralloc (80);

mov (eax, s);

...

strfree(s);
Posted on 2003-06-03 03:55:57 by V Coder
Yes, doing blocked I/O, rather than character at a time I/O, is much faster.
Indeed, it's a good thing that HLA's fileio routines already do blocked I/O for you
(the fileio.getc routine maintains its own buffers) or you would be seeing a one-to-two orders of magnitude difference in performance rather than three-to-four times!

Even faster still is to use memory mapped I/O. Memory mapped I/O, as its name implies, just maps all the file data directly to memory and you access it via a pointer. Very, very, fast because it uses the virtual memory subsystem for all disk I/O.

The only catch is that, currently, you have to make the Win32 API calls directly to set up access to a memory mapped file. I've been threatening to write an HLA Standard Library module to make the use of memory mapped files portable between Windows and Linux, but I've been trying to get a few other projects out of the way first...

Maybe in a month or two.
Cheers,
Randy Hyde
Posted on 2003-06-03 14:26:32 by rhyde
What are the API instructions for memory-mapped IO please?
Posted on 2003-09-30 22:59:22 by V Coder

What are the API instructions for memory-mapped IO please?


Well, look at CreateFileMapping, MapViewOfFile, and other such routines.
One piece of good news, HLA v1.57 *will* have memory mapping added
to the HLA Standard Library (and it will be portable between Windows
and Linux).
Cheers,
Randy Hyde
Posted on 2003-10-01 11:32:42 by rhyde
I've attached a quick example that demonstrates how to process memory-mapped files in HLA. I've actually provided a class that you can use to manipulate memory-mapped file objects (this class will become the basis for the support in the HLA Standard Library).

Note: I just uploaded a new version of this attachment...
Enjoy,
Randy Hyde
Posted on 2003-10-01 12:50:12 by rhyde