File size and the secret of the space occupied

  
                              

1. The difference between "file size" and "space occupied"

For the sake of understanding, let's look at two examples:

Example 1 Find the Ersave2.dat file on the D drive. Right click on the file and select "Properties" to open the dialog shown in Figure 1. We can see that the actual size of Ersave2.dat is 655,628 Bytes, but the space it occupies It is 688,128 Byte, and the difference between the two is 32KB.

Example 2 is the same file. If you copy it to the A disk, you will find that the actual size and space of the file are basically the same, the same as 640KB, but the number of bytes is slightly different. After copying it to the C drive and viewing its properties, you will be surprised to find that its size and space difference are different!

Obviously, in these three cases, the actual size of the file has not changed, but the space it occupies on different disks has changed. In fact, as long as we understand the storage mechanism of files on disk, it is not difficult to understand the above three situations. The size of the file is actually the number of bytes actually owned by the file. It is measured in Byte. As long as the file content and format do not change, the file size will not change. However, the space occupied by the file on the disk is not measured in Byte. The smallest unit of measurement is "Cluster".

Tips: 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 may include 2, 4, 8, 16, 32 or 64 sectors. Obviously, a cluster is a logical concept used by an operating system, not a physical property of a disk.

In order to better manage disk space and read data from the hard disk more efficiently, the operating system specifies that only one file can be placed in a cluster, so the space occupied by the file can only be an integer of the cluster. Double; if the actual size of the file is less than a cluster, it also takes up a cluster of space. Therefore, in general, the space occupied by the file is slightly larger than the actual size of the file. In a few cases, 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 occupied space.
2. Partition Format and Cluster Size

In Example 2, the space occupied by the same file on different disk partitions is not the same size, which is caused by the different sizes of different disk clusters. The size of the cluster is mainly determined by the partition format and capacity of the disk, and the corresponding relationship is shown in Table 1.

author using FAT partition floppy capacity 1.44MB, the cluster size is 512 Byte (a sector); C to FAT 32 partition plate, capacity of 4.87GB, the cluster size is 8KB; D disc to FAT 32 The partition has a capacity of 32.3 GB and a cluster size of 32 KB. When calculating the space occupied by a file, you can use the following formula:

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

Space occupied = number of clusters × disk cluster size

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

3. Easily view cluster size

1View cluster size with Chkdsk

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, you can click "Start → Run", type "CMD" and press Enter, then type "C:" and press Enter, then enter "Chkdsk" and press Enter. A moment later, from its analysis results, we can get the cluster size of the C disk, but it refers to the cluster as "allocation unit" or "Allocation unit", as shown in Figure 2.

② use PQ Magic and other disk tools to detect

Disk Utility will have a lot of disk information display. For example, in PQ Magic, select the disk partition to be viewed, and then right-click and select the "Advanced → Adjust Cluster Size" function, you can see the cluster size currently set by the disk from the displayed dialog box, as shown in Figure 3. Show.

3 Manual View

Manually create a text document of less than 100 bytes. Then copy the file to the disk partition where you want to view the cluster size, and display the properties of the file under Windows. The value displayed at the "Space occupied" is the cluster size.

Copyright © Windows knowledge All Rights Reserved