The MASM Forum

Miscellaneous => The Orphanage => Topic started by: xanatose on September 17, 2014, 05:10:19 AM

Title: Need some advice on copying a file in front of another
Post by: xanatose on September 17, 2014, 05:10:19 AM
Using windows API
What would be the fastest way to copy a multi-mega byte file to the front of a multigigabyte file?

Lets say A is the file I want to copy in front of B.

Right now (using CreateFile, ReadFile, WriteFile). Leaving error checking from the steps.

1. Create a temp file (name it C)
2. Copy A to C
3. Copy B to the end of C
4. Rename B to D
5. Rename C to B
6. Delete D

It works, but it takes a really long time. I wonder if there is a faster way. (Without destroying A)
Title: Re: Need some advice on copying a file in front of another
Post by: dedndave on September 17, 2014, 05:55:54 AM
some file sizes simply take time

there is a slight improvement to the last few steps - but, i doubt you'd notice any speed improvement
1. Create a temp file (name it C)
2. Copy A to C
3. Copy B to the end of C
4. Delete B
5. Rename C to B

Title: Re: Need some advice on copying a file in front of another
Post by: KeepingRealBusy on September 17, 2014, 07:47:14 AM
If there is no need to keep the original B file, then just copy the A file to the end of B.

Dave.
Title: Re: Need some advice on copying a file in front of another
Post by: adeyblue on September 17, 2014, 09:25:48 AM
Extend B with the size of A using SetFilePointer & SetEndOfFile. Use MapViewOfFile to map chunks of B (starting at the end) and memmove the existing data forward. When done, memcpy A to the space left at the start.

No idea if it'll be any faster but it should make less mess of the file system.
Title: Re: Need some advice on copying a file in front of another
Post by: dedndave on September 17, 2014, 10:07:01 AM
what size read/write buffer are you using ?
i would probably use something like 32 or 64 KB
although, you may have to play with the size for performance