Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] file size vs occupied space on disc

Status
Not open for further replies.

abil10

Newbie
Joined
Oct 27, 2018
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
26
hello everyone,

please could any one support to exlain below behaviour.

I Created a text file with exactly 4095 Bytes,but the file occupied disk space is 4096 bytes .

delq.png


i added some content to the original file to have a size of 4096 bytes, but the occupied space on disk remained the same. exactly 4096 (2 ^12)

dele.png

Thnxs guys
 

This can be for two reasons:
1. Typically a terminator character is added to the end of text files,
2. Granularity of the filing system.

Unfortunately, the size of your file fits a possible cluster size so it isn't easy to tell which it is. Clusters are the MINIMUM allocation size of a file. For example, if you saved a single byte file and cluster size was 4096 bytes, it would use 4096 bytes to store it. If the file was one byte bigger it would need two clusters even though the second one was almost empty so 8192 bytes would be saved.

The cluster size depends on the filing system used but essentially, it is the smallest 'unit' of storage. Every cluster has a number which is used to tell the filing system, through the directory, where things are stored so smaller clusters require more indexing numbers and hence more space taken up by the directory. There is a compromise between the size of the index (technically called a FAT or File Allocation Table) and the amount of space wasted in unused parts of clusters.

Sizes are always powers of two so 4096 (=2^12) is a likely candidate for the cluster size your OS is using.


Brian.
 
  • Like
Reactions: abil10

    abil10

    Points: 2
    Helpful Answer Positive Rating
Thnxs Brian,
so in this case, there is no difference if we store small or big files ?
 

Try it and see. Make a text file with a single letter in it and save it. Use a simple text editor, not a word processor because they add extra formatting and authoring data. See how big a one letter file is, that will be the storage cluster size.

A cluster is the smallest 'container' anything can be saved in so whatever size a file really is, it will always be a multiple of cluster size, even if the final cluster is partially empty. Some OS use different cluster sizes depending on the capacity of the whole disk. This is because each cluster has an index number and all the index numbers are stored in a table (FAT). Because the FAT is usually a fixed size it makes sense to use all the entries to cover all the disk so the cluster sizes are adjusted accordingly.

My OS uses the EXT4 filing system with 512 byte clusters which makes it very efficient, the most wasted space if a one byte file is saved is 511 bytes. Some OS waste as much as 32K bytes.

Brian.
 
  • Like
Reactions: abil10

    abil10

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top