[LC++]file copying

Kar G Lim tuxcppsubscription at kimay.net
Wed Jan 28 17:56:01 UTC 2004


Anyone can see the source:

http://www.gnu.org/software/fileutils/fileutils.html

just get the source

----- Original Message ----- 
From: Jan Pfeifer <pfjan at yahoo.com.br>
To: <tuxcpprogramming at lists.linux.org.au>
Sent: Wednesday, January 28, 2004 7:41 PM
Subject: Re: [LC++]file copying


> hi Larry,
> 
> copying the file byte by byte incurs in a high overhead (one function
> call per byte). Try using a bigger buffer. Check attached code.
> 
> :)
> 
> jan
> 
> ps.: i did some measuring with the code, and it still takes 1.5 the time
> /bin/cp takes to copy. Anyone knows how /bin/cp does this faster ? I
> would guess it somehow manages to avoid a buffer copying, maybe using
> memory mapped files ...
> 
> On Wed, 2004-01-28 at 00:57, larry wrote:
> > I have a problem related to the speed of copying files in C++ on
> > linux. I need to automate a process to copy files from one directory
> > to another for media management. Anyway, the following code is what I
> > have been using and it is not nearly fast enough. The entire focus of
> > this application is speed. In fact in Windows, I am getting at least 5
> > times the speed from a VB app that I am using. I know I must be doing
> > something wrong. I am compiling on a one processor machine and moving
> > it to the test equipment which has four processors and 4 gigs or RAM.
> > I wonder should I compile it there to see if it runs better or is
> > there a better method for copying files from one directory to another.
> > The file system is Reiserfs on a gentoo installation. The machine that
> > I am compiling on is ext3 on Redhat.
> > 
> > IPFile = fopen("/home/this.jpg","r");
> > OPFile = fopen("/mediafiles/this.jpg","w");
> > while ((c = fgetc(IPFile)) != EOF)
> > {
> > fputc(c, OPFile);
> > }
> > fclose(IPFile);
> > fclose(OPFile);
> > 
> > Anyway, I am at a loss. There has to be a better method than this.
> > Thanks.
> > 
> > ---
> > Larry Lines
> 




More information about the tuxCPProgramming mailing list