+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Newbie level 3
    Points: 74, Level: 1

    Join Date
    Oct 2018
    Posts
    3
    Helped
    0 / 0
    Points
    74
    Level
    1

    file size vs occupied space on disc

    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 .

    Click image for larger version. 

Name:	delq.png 
Views:	0 
Size:	1.1 KB 
ID:	150827


    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)

    Click image for larger version. 

Name:	dele.png 
Views:	3 
Size:	15.0 KB 
ID:	150828

    Thnxs guys

    •   AltAdvertisment

        
       

  2. #2
    Super Moderator
    Points: 76,699, Level: 67
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,547
    Helped
    4181 / 4181
    Points
    76,699
    Level
    67

    Re: file size vs occupied space on disc

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  3. #3
    Newbie level 3
    Points: 74, Level: 1

    Join Date
    Oct 2018
    Posts
    3
    Helped
    0 / 0
    Points
    74
    Level
    1

    Re: file size vs occupied space on disc

    Thnxs Brian,
    so in this case, there is no difference if we store small or big files ?



    •   AltAdvertisment

        
       

  4. #4
    Super Moderator
    Points: 76,699, Level: 67
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,547
    Helped
    4181 / 4181
    Points
    76,699
    Level
    67

    Re: file size vs occupied space on disc

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

--[[ ]]--