Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

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.

share|improve this question

migrated from stackoverflow.com May 9 '12 at 9:26

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Dennis, Dave M, BBlake, TFM, jdh Feb 6 '13 at 15:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
This is quite clearly not a programming question. –  unwind May 9 '12 at 9:24
3  
And BTW, if you use disk compression, the size on disk can be smaller than the basic size. –  Jerry Coffin May 9 '12 at 9:25
    
sorry but i wanted to read the size of the file programmatically. I was confused as to which size i will be getting. That is where i have got this doubt.. –  Manty May 9 '12 at 9:26
    
... or if you use sparse files –  jpalecek May 9 '12 at 9:26

1 Answer 1

up vote 10 down vote accepted

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.

share|improve this answer
    
Thanks.. But is this not wastage of memory? –  Manty May 9 '12 at 9:30
    
@happy2Help: yes it is, but it brings other benefits which are much more important: speed mostly. It's a tradeoff. –  nightcracker May 9 '12 at 9: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 –  Manty May 9 '12 at 9: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 9 '12 at 9:53
    
@nightcracker Thanks for the information.. –  Manty May 9 '12 at 10:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.