Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!image.soe.clarkson.edu!news From: cline@cheetah.ece.clarkson.edu (Marshall Cline) Newsgroups: comp.lang.c Subject: Re: questions about a backup program for the MS-DOS environment Message-ID: Date: 3 May 90 17:06:11 GMT References: <255@uecok.UUCP> <1990Apr25.125806.20450@druid.uucp> <12459@wpi.wpi.edu> <2484@dataio.Data-IO.COM> Sender: news@sun.soe.clarkson.edu Reply-To: cline@sun.soe.clarkson.edu (Marshall Cline) Followup-To: comp.lang.c Organization: (I don't speak for the) ECE Dept, Clarkson Univ, Potsdam, NY Lines: 44 In-reply-to: bright@Data-IO.COM's message of 2 May 90 21:39:58 GMT In article <2484@dataio.Data-IO.COM> bright@Data-IO.COM (Walter Bright) writes: >In article <12459@wpi.wpi.edu> jhallen@wpi.wpi.edu (Joseph H Allen) writes: >>In article <1990Apr25.125806.20450@druid.uucp> darcy@druid.UUCP (D'Arcy J.M. Cain) 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): >> [asm example deleted] >There is no point in going to asm to get high speed file copies. Since it >is inherently disk-bound, there is no sense (unless tiny code size is >the goal). Here's a C version that you'll find is as fast as any asm code >for files larger than a few bytes (the trick is to use large disk buffers): [example deleted] Note that Walter used read()/write() as opposed to fread()/fwrite(). In Turbo-C, it's even faster (probably 2 to 3 times faster!) to use _read() and _write(), since read()/write() can end up deleting/inserting ^J if the files are in text mode. I found fread()/fwrite() in Turbo-C to be embarassingly & surprisingly slow. After tracing them, I found they resolved to loops of fgetc()/fputc() rather than the seemingly more obvious read()/write(), apparently since fgetc()/fputc() know about buffering. However it wouldn't be hard to fix fread()/fwrite() to do it `right'! Marshall -- =============================================================================== Marshall Cline/ECE Department/Clarkson University/Potsdam NY 13676/315-268-3868 cline@sun.soe.clarkson.edu, bitnet: BH0W@CLUTX, uunet!clutx.clarkson.edu!bh0w Career search in progress: ECE faculty. Research oriented. Will send vita. ===============================================================================