questions about a backup program for the MS-DOS environment

e89hse at rigel.efd.lth.se e89hse at rigel.efd.lth.se
Tue May 8 09:14:12 AEST 1990


In article <2682 at ecs.soton.ac.uk>, sra at ecs.soton.ac.uk (Stephen Adams) writes:
>>In article <255 at uecok.UUCP> dcrow at uecok (David Crow -- ECU Student) writes:
>>>      - possibly a faster copying scheme.  the following is the
>>>         code I am using to copy from one file to another:
>>>
>>>            do
>>>            {
>>>               n = fread(buf, sizeof(char), MAXBUF, infile);
>>>               fwrite(buf, sizeof(char), n, outfile);
>>>            } while (n == MAXBUF);        /* where MAXBUF = 7500 */
>>>
>>Try:
>>     while ((n = fread(buf, sizeof(char), BUFSIZ, infile)) != 0)
>>		fwrite(buf, sizeof(char), n, outfile);
>>
>>By using BUFSIZ instead of your own buffer length you get a buffer size
>>equal to what the fread and fwrite routines use.  
>
>No, no, no Yuck!  Don't use the C functions, and don't use such tiny buffers.
>(no wonder it's so slow :-)
>
>   Try (in small or tiny model):
>
>
>	... 30 lines of *heavily* machine dependent C ...
>
 Why mashine dependent and why machine code, just replace 7500 (MAXBUF) with
something more normal like 0x4000 and fread and fwrite with read and write
respectivly. (And open with O_BINARY). If you wanna make it faster just
increase the buffer size.


 Henrik Sandell



More information about the Comp.lang.c mailing list