This is because 4K is the default cluster size for drives up to 16 TB. Therefore, when choosing the size of the buffer, it makes sense to allocate a buffer in several cluster sizes.
A cluster is the smallest distribution unit for a file, so if a file contains only 1 byte, it will consume 4 KB of physical disk space. And the 5K file will result in an 8K distribution.
Update : added code sample to get disk cluster sizeusing System;
using System.Runtime.InteropServices;
class Program
{
[DllImport("kernel32", SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetDiskFreeSpace(
string rootPathName,
out int sectorsPerCluster,
out int bytesPerSector,
out int numberOfFreeClusters,
out int totalNumberOfClusters);
static void Main(string[] args)
{
int sectorsPerCluster;
int bytesPerSector;
int numberOfFreeClusters;
int totalNumberOfClusters;
if (GetDiskFreeSpace("C:\\",
out sectorsPerCluster,
out bytesPerSector,
out numberOfFreeClusters,
out totalNumberOfClusters))
{
Console.WriteLine("Cluster size = {0} bytes",
sectorsPerCluster * bytesPerSector);
}
else
{
Console.WriteLine("GetDiskFreeSpace Failed: {0:x}",
Marshal.GetLastWin32Error());
}
Console.ReadKey();
}
}
source
share