If you are asking whether you should specify 2048 or 2 * 1024, there is no rule. Some programmers consider 2 * 1024 to be more informative to a person reviewing the code. 1024 is 1K. if you need a buffer size, for example, 12K, does it provide more information to the reader to say 12 * 1024 or 12288? Specifying 2 * 1024 is not less efficient at runtime than specifying 2048 because the compiler makes the calculation.
Joined: Jul 09, 2007
I think so also..
I think your response answers half of my question.
But then, I would like to know when it is adviseable to create a buffer such as
and when it is right to just create a 1KB buffer.
My guess is that is it related to the file size???
The ideal size is the page size used, but that's determined by the OS and/or the file system. Optimal buffer sizes on one system may be just so-so on other systems.
Thanks. So does it mean, I could tweak this anytime and check if the performance is still good?
Sure. Try different buffer sizes and transfer the same file, timing how long it takes to do the transfer. Make sure you use a large file otherwise you'll be including a larger amount of code unrelated to file copying.