Why is the file size different from the occupied space?

A file, whether stored in hard disk space or other mobile storage space, the size of the file itself is smaller than the space occupied;

  For example, a 12K Txt file occupies more than 12K of space . Why is this?

  In addition, there are also situations where the same file, stored in different disk partitions and different operating system environments, takes up different space! This is why?

  ①The difference between file size and space occupied

  The size of a file is actually the number of bytes actually contained in the file content. It is measured in Bytes. As long as the file content and format do not change, the file size will not change. However, the space occupied by a file on the disk is not measured in Byte. Its smallest measurement unit is "Cluster".

  What is a cluster?

  The file system is the interface between the operating system and the drive. When the operating system requests to read a file from the hard disk, it will request the corresponding file system (FAT 16/32/NTFS) to open the file. A sector is the smallest physical storage unit of a disk, but because the operating system cannot address a large number of sectors, the operating system combines adjacent sectors to form a cluster, and then manages the cluster. Each cluster can include 2, 4, 8, 16, 32, or 64 sectors. Obviously, the cluster is a logical concept used by the operating system, not the physical characteristics of the disk.

  In order to better manage the disk space and read data from the hard disk more efficiently, the operating system stipulates that only one file can be placed in a cluster, so the space occupied by the file can only be an integer multiple of the cluster; and if the file is actually If the size is smaller than a cluster, it also occupies the space of a cluster. Therefore, under normal circumstances, the space occupied by the file is slightly larger than the actual size of the file. Only in a few cases, that is, when the actual size of the file is exactly an integer multiple of the cluster, the actual size of the file will be exactly the same as the space occupied.

  ②Partition format and cluster size

  When calculating the space occupied by a file, the following formula can be used:

  Number of clusters = rounding (file size/cluster size) + 1

  Occupied space = cluster number × disk cluster size

  The file size and cluster size in the formula should be in bytes, otherwise errors may occur. If you want to use KB as the unit, divide the number of bytes by 1024. Using the above calculation formula, the actual space occupied by the ersave2.dat file can be calculated.

  ③Easily view the cluster size

  1. Use Chkdsk to view the cluster size

  In the Windows operating system, we can use the Chkdsk command to view the cluster size of the hard disk partition. For example, if we want to view the cluster size of the C drive under Windows XP, we can click "Start→Run", type "CMD" and press Enter, then type "C:" and press Enter, and then type "Chkdsk" and press Enter. After a while, from its analysis results, we can get the cluster size of Disk C, but it calls the cluster "allocation unit" or "allocation unit".

 

 

Undertake programming in Matlab, Python and C++, machine learning, computer vision theory implementation and guidance, both undergraduate and master's degree, salted fish trading, professional answers please go to know, please contact QQ number 757160542 for details, if you are the one.

 

Guess you like

Origin blog.csdn.net/weixin_36670529/article/details/113903599
Recommended