Search code examples
c++file-copying

Force file copy with very lower resources requirements


i have a program written in C++ that is permanently writing files to the Harddisk. The Harddisk used is fast enough to handle this without slowing down the application.

Now from time to time i like the program to copy/sync the files to our server. The challenge im facing is that i don't want the copy to use many system resources so it's not slowing the application or the writing of new files.

I guess running the copy/sync on a background thread will help somewhat but it will still stress the Harddisk and slow down writing of new files right?

So i guess my question is how can i control the speed of a copy operation? Or is there another better way to do this?

Any help is really appreciated.

Dennis


Solution

  • Re-reading this - "Now from time to time i like the program to copy/sync the files to our server. The challenge im facing is that i don't want the copy to use many system resources so it's not slowing the application or the writing of new files."

    This means that you're not actually trying to avoid working the box hard; you just don't want to fall behind on your other file work.

    I'd create a background thread that does all your disk access; and provide 2 queues for it to work on. The first being the new files to write; the 2nd being the files to copy. This thread can then use the disk at full speed by working on chunks at a time; with the priority being getting a chunk from the new file area. This will allow you to start doing a copy; and then stop copying entirely while there's lots of files to process (in case there's a burst) and then copy as fast as you can once it's all been processed.