CompuServe Thread

#Reading a file

6 messages in this thread
#68153From: Michael A McCormickOct 3, 1989 9:14 PM
If you absatively, posolutely HAVE to read in an ASCII file a character at a time, what is the fastest command to do it with? getc()? read()? The only other constraint is that I need to read the control character(s) (CR &| LF) in the file as well. Or, perhaps, is there a way to suck a moderate size file (under 10,000 bytes) into a memory slot in one gulp and work with it there? I've noticed some difficulty useing a large buffer value in read(), is there some maximum value? -Mike
#68175From: Mike Roth/LatticeOct 3, 1989 11:40 PM
Mike, If you really want the fastest way to read characters from a file, I'd recommend you go directly to the AmigaDOS functions (Open(), Read(), Close()). These functions are documented in the AmigaDOS reference manual. No matter what method you use, you will gain speed by reading in multiple characters. You shouldn't have any problems reading in 10,000 characters into a buffer with either Read() or read(). By the way, using the getc() type functions actually reads in more than one character at a time. The buffering is just transparent to the caller. I hope this helps. — Mike Roth
#68219From: M2S/Phil CampOct 4, 1989 8:07 AM
Calling the AmigaDOS Read() routine for single-character IO is the worst thing you could do! It gos VERY slowly.
#68222From: Khalid AldoseriOct 4, 1989 10:18 AM
Martin, right. It's best to use Read() into a temp buffer of say around 10k, then process that once char at a time. That works pretty fast depending on your routine that gets each char. I've used Read() on reads of 1 meg in size at one time.. it's pretty fast especially with FFS. (grin) Khalid.
#68223From: M2S/Phil CampOct 4, 1989 11:42 AM
A I've mentioned this before elsewhere, but the true fastest method for reading single characters from a file is the one used by the SingleCharDOS module supplied with M2Sprint. The module uses double-buffered asynchronous IO to achieve truely remarkable performance. Basically, there are two input buffers of equal size. When the file is first opened, a packet is sent to the file system requesting some data to fill up buffer #1. When the first call to read a character is made, this char is taken from the first buffer. At that time, a background request is sent to DOS to have it read some chars in the second buffer. While the program is busy processing the cvhars in the first buffer, the second buffer is being filled by background disk DMA. When all characters from the first buffer have been read, you then start reading fom the second buffer and send a request to DOS to start filling the first buffer again. This approach is tricky to implement, but it gives amazing results.
#68245From: Mike Roth/LatticeOct 4, 1989 5:07 PM
Martin, I based that suggestion on (1) he really did want to read one character at a time, and (2) he did not want to get into involved routines such as going to the trackdisk.device, etc. If you check my suggestions, I did say that it is much better to read a block of characters at a time. Just trying to clarify things. — Mike Roth