question regarding file size

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sometimes the "size on disk" of a file is much larger than the "size" of the
file. How can that be avoided? In other words, what should be done so the
"size on disk" is about the same as the "size"?
 
You're referring to Cluster size. By default XP uses a 4-Kbyte cluster
size. While you can use anything from 512-Bytes up to 64-KBytes it
isn't possible to have all files utilize 100% of their cluster allocation. A
volume will always have "Slack Space" or empty portions of a cluster
that aren't filled.
 
b11_ said:
Sometimes the "size on disk" of a file is much larger than the "size" of the
file. How can that be avoided? In other words, what should be done so the
"size on disk" is about the same as the "size"?

For a simple explanation, the physical size of a file by itself is its
real size in terms of bytes. OTOH, files are stored in clusters on a
disk. The "size on disk" represents the total size based on the number
of clusters that were used to store the file. For example, if a cluster
is set at 512 Bytes, then any size of file from 1 to 512 Bytes in this
cluster will be shown as 512 Bytes. Or, if spread over 2 clusters, then
the disk size would be 1,024 Bytes.
 
Sometimes the "size on disk" of a file is much larger than the "size" of the
file.


In fact, almost always.

How can that be avoided?


It can't.

In other words, what should be done so the
"size on disk" is about the same as the "size"?



To understand the difference between "size" and "size on disk," and
why they differ, you need to understand how disk space is allocated to
files. It's done in units called "clusters." The size of the cluster
varies, depending on what file system is used (NTFS or FAT32) and the
size of the partition. With NTFS, the cluster size is normally
4Kbytes; with FAT32, it varies up to 64KB.

That means that the amount of disk space a file uses (size on disk) is
always a multiple of its cluster size. Assuming for example that you
are using NTFS, with a 4K cluster size, any file between 1 byte and
4096 bytes uses an entire cluster; any file between 4097 and 8192
bytes uses two clusters; and so on.

So any file with a size that is not an exact multiple of the drive's
cluster size wastes a portion of its last cluster, and that's why size
on disk is almost always more than size. That wasted space is known as
"cluster overhang" or "slack." Assuming a random distribution of file
sizes (not quite true, but close enough for our purposes here), on the
average each file wastes an amount of disk space equal to half the
cluster size. So the total waste due to slack is roughly equal to the
number of files on the drive multiplied by half the cluster size.

Now that you understand the difference between "size" and "size on
disk," let me point out that in today's world of very low priced hard
drives, the amount of space wasted to slack is insignificant. If you
have 100,000 files on an 80GB NTFS drive (substitute your own numbers
and redo the calculation, if those aren't accurate), you will waste
100,000 times 2048 bytes, or about 200MB of disk space. 200MB may seem
like a lot of bytes, but considering that that 80GB drive probably
cost something around $80US, it's only about 20 cents worth--certainly
not something to get excited about.
 
b11_ said:
Sometimes the "size on disk" of a file is much larger than the "size"
of the file. How can that be avoided? In other words, what should be
done so the "size on disk" is about the same as the "size"?

How many 1-gallon buckets does it take to hold five quarts?

Size of liquid: 5 quarts
Size of container: 8 quarts

It could be even more bizarre:
How many 5,000 gallon tanks does it take to hold five quarts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top