News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Need some advice on copying a file in front of another

Started by xanatose, September 17, 2014, 05:10:19 AM

Previous topic - Next topic

xanatose

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)

dedndave

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


KeepingRealBusy

If there is no need to keep the original B file, then just copy the A file to the end of B.

Dave.

adeyblue

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.

dedndave

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