5

I created a simple text file. I saw its size. it was 0 bytes. Then i entered alphabet 'a' and checked the size of it. IT says:

Size : 1 bytes

Size on disk: 4.00 KB(4096 bytes)

What is the difference? And why two different values for the same data? OS I am referring to is Windows.

fixer1234
  • 27,486
Sandeep
  • 633

1 Answers1

10

The hard drive can be seen as a long string of bits and bytes. The way the hard drive can be used as a thing to hold folders and files is using a filesystem.

Most filesystems use blocks to hold files. Each file consists of one or more blocks. So a file takes at least the size of one block, in your case 4 kilobyte (which is a small block).

This is all highly dependent on which filesystem you use, but this is most likely the explanation.

orlp
  • 1,547
  • Thanks.. But is this not wastage of memory? – Sandeep May 09 '12 at 09:30
  • @happy2Help: yes it is, but it brings other benefits which are much more important: speed mostly. It's a tradeoff. – orlp May 09 '12 at 09:32
  • hmm interesting.. This must be a common problem, if there is a name to this, kindly state it. will find more on google about this.. Nice Answer.. +1 for keeping it short and understandable.. thanks – Sandeep May 09 '12 at 09:37
  • 2
    @happy2Help The process that allocates files to blocks is called "blocking". The space wasted by allocating only whole, unused blocks to a file and probably not filling the last one completely is called "slack space". Some modern filesystems attempt to overcome this with a process called "block suballocation" which, as the name implies, allows a block to contain parts of multiple files. – Indrek May 09 '12 at 09:53
  • If it is fat or ntfs file system, fragmentation can add to "size on disk" – Moab May 09 '12 at 14:08
  • @Moab that is wrong. Even if a file is 100% fragmented, i.e. it doesn't consist of any contiguous blocks, still only the last block will be partially filled. – Ro-ee Sep 20 '16 at 23:19