Xref: utzoo comp.lang.c:28514 comp.lang.misc:4974 comp.sys.ibm.pc:50176 comp.sys.ibm.pc.programmer:1342 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!bloom-beacon!eru!luth!sunic!lth.se!E89HSE@rigel.efd.lth.se From: e89hse@rigel.efd.lth.se Newsgroups: comp.lang.c,comp.lang.misc,comp.sys.ibm.pc,comp.sys.ibm.pc.programmer Subject: Re: questions about a backup program for the MS-DOS environment Message-ID: <00936556.AD7E6100@rigel.efd.lth.se> Date: 7 May 90 23:14:12 GMT References: <255@uecok.UUCP> <1990Apr25.125806.20450@druid.uucp> <12459@wpi.wpi.edu>,<2682@ecs.soton.ac.uk> Sender: newsuser@lth.se (LTH network news server) Reply-To: e89hse@rigel.efd.lth.se Organization: Lund Institute of Technology,Lund, Sweden Lines: 33 In article <2682@ecs.soton.ac.uk>, sra@ecs.soton.ac.uk (Stephen Adams) writes: >>In article <255@uecok.UUCP> dcrow@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