Saving a file on the network
I have a file about 7MB in size that is saved in my local folder in a matter of seconds. However, it takes minutes to save this file to a network location. I am wondering what I can do to speed this up. Here are my current options:
- Save the data to a temporary file on your local computer, then copy the temporary file to the network path . I will probably do this as it is the easiest and hardest hit for the dollar.
- Use
SetFilePointerEx()
andSetEndOfFile()
. I thought this might be helpful based on the answer to this question: Creating a large file on Windows - The buffer writes . I could cache the data for writing myself and hide when the buffer is full, but wouldn't that be redundant with the caching already done by the OS?
# 1 seems like the best option, but I'm wondering if anyone has any advice on the best way to speed up saving network paths?
Edit: The network is on a gigabit LAN, so speed shouldn't be an issue. It takes about 1 second to copy the file to the network path. I just noticed that we are calling WriteFile () on smaller chunks of data, then we should probably do that, so optimizing higher-level code to write larger chunks will probably help, but the speed difference is still so significant that there is still a question.
a source to share
You will need aovid read-modify-write operations. Usually you need to write blocks of at least 4KB, possibly higher authority 2. The reason is that to add one byte, you usually need to read the last block of the file, add one byte and write back a new block.When writing 4KB blocks (only ) each record usually ends as a new block at the end of the file.
Caching should help you here, but caching is not perfect. This can help to open the file exclusively. If you deny read access, the OS may notice that clearing the cache is not too important for other applications.
CopyFile can be fast because it can do the same.
a source to share