I have this simple code which combines text files into one text file :
void Main()
{
const int chunkSize = 2 * 1024; // 2KB
var inputFiles = new[] { @"c:\1.txt", @"c:\2.txt", @"c:\3.txt" };
using (var output = File.Create(@"c:\output.dat"))
{
foreach (var file in inputFiles)
{
using (var input = File.OpenRead(file))
{
var buffer = new byte[chunkSize];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
}
}
}
}
My question is about the chunkSize
size.
How can I know if the number I've chosen is the right one ? (1024*2)
I'm trying to find the idle formula :
Assuming each file size is F mb
, and I have R mb
of Ram and the block size of my Hd is B kb
- is there any formula which I can build to find the idle buffer size ?