为什么磁盘上的文件大小不同?
Why is the size of a file different on disk?
当我们在 Windows Explorer 等任何文件管理软件中查看文件大小时,我们会看到两种不同的大小,一种显示为 Size另一个读取 磁盘大小。
为什么这两个不同?
磁盘上的大小是否包括一些开销,例如它在文件分配 Table (FAT) 中的条目?能详细点吗?
当我们以编程方式查询文件的大小时,它总是 returns 与磁盘大小无关的大小。它从哪里得到这个数字? OS 是否必须读取整个文件的内容来确定此大小或仅查找文件分配 table?
在超级用户上找到 this。
他说的话:
We know that a disk is made up of Tracks and Sectors. In Windows that means the OS allocates space for files in "clusters" or "allocation units".
The size of a cluster can vary, but typical ranges are from 512 bytes to 32K or more. For example, on my C:\ drive, the allocation unit is 4096 bytes. This means that Windows will allocate 4096 bytes for any file or portion of a file that is from 1 to 4096 bytes in length.
If I have a file that is 17KB (kilo bytes), then the Size on disk would be 20.48 KB (or 20480 bytes). The calculation would be 4096 (1 allocation unit) x 5 = 20480 bytes. It takes 5 allocation units to hold a 17KB file.
Another example would be if I have a file that is 2000 bytes in size. The file size on disk would be 4096 bytes. The reason is, because even though the entire file can fit inside one allocation unit, it still takes up 4096 of space (one allocation unit) on disk (only one file can use an allocation unit and cannot be shared with other files).
So the size on disk is the space of all those sectors in which the file is saved. That means,usually, the size on disk is always greater than the actual size.
So the actual size of a file(s) or folder(s) should always be taken from the Size value when viewing the properties window.
当我们在 Windows Explorer 等任何文件管理软件中查看文件大小时,我们会看到两种不同的大小,一种显示为 Size另一个读取 磁盘大小。
为什么这两个不同?
磁盘上的大小是否包括一些开销,例如它在文件分配 Table (FAT) 中的条目?能详细点吗?
当我们以编程方式查询文件的大小时,它总是 returns 与磁盘大小无关的大小。它从哪里得到这个数字? OS 是否必须读取整个文件的内容来确定此大小或仅查找文件分配 table?
在超级用户上找到 this。 他说的话:
We know that a disk is made up of Tracks and Sectors. In Windows that means the OS allocates space for files in "clusters" or "allocation units".
The size of a cluster can vary, but typical ranges are from 512 bytes to 32K or more. For example, on my C:\ drive, the allocation unit is 4096 bytes. This means that Windows will allocate 4096 bytes for any file or portion of a file that is from 1 to 4096 bytes in length.
If I have a file that is 17KB (kilo bytes), then the Size on disk would be 20.48 KB (or 20480 bytes). The calculation would be 4096 (1 allocation unit) x 5 = 20480 bytes. It takes 5 allocation units to hold a 17KB file.
Another example would be if I have a file that is 2000 bytes in size. The file size on disk would be 4096 bytes. The reason is, because even though the entire file can fit inside one allocation unit, it still takes up 4096 of space (one allocation unit) on disk (only one file can use an allocation unit and cannot be shared with other files).
So the size on disk is the space of all those sectors in which the file is saved. That means,usually, the size on disk is always greater than the actual size.
So the actual size of a file(s) or folder(s) should always be taken from the Size value when viewing the properties window.