Does the size on disk always have to be an even number?

This is a discussion on Does the size on disk always have to be an even number? within the C Programming forums, part of the General Programming Boards category; I have been examining my files and have found that the size on disk always turns out even even when ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    150

    Does the size on disk always have to be an even number of bytes?

    I have been examining my files and have found that the size on disk always turns out even even when size is not even.
    Would this mess up my program if it created a file with an odd number of chars?
    Last edited by Once-ler; 03-02-2013 at 02:51 AM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,433
    Nope.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    150
    thanks

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    It may seem that way probably because the file is optimized for easier disk storing, for example the minimum "on disk" size my files have are 4 KBytes. This may also vary for different file systems.
    Devoted my life to programming...

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    There's a difference between logical file size and physical file size. The logical size may be any number, odd or even, from 0 to as big as the file system allows. The logical size is a multiple of the size of a disk sector.
    Note also that it may not necessarily be greater than or equal to the physical size. Compressed files may have a smaller physical size than their logical size.

    If the size is always even then that could be an indication that your files are UTF16 for example.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Examining MBR and Printing Total Disk Size in Bytes
    By pantherman34 in forum C Programming
    Replies: 8
    Last Post: 04-30-2010, 03:27 PM
  2. hard disk serial number
    By vijayaroli in forum Windows Programming
    Replies: 1
    Last Post: 08-31-2006, 03:00 AM
  3. how to find volume serial number of disk using c
    By sudhirn in forum C Programming
    Replies: 0
    Last Post: 03-11-2004, 08:50 AM
  4. getting disk size information
    By Turek in forum C++ Programming
    Replies: 5
    Last Post: 07-31-2002, 02:52 AM
  5. Need help discovering disk-size
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-17-2001, 01:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21