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)
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
If there is no need to keep the original B file, then just copy the A file to the end of B.
Dave.
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.
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