Ako môže byť veľkosť súboru nula?

Obsah:

Ako môže byť veľkosť súboru nula?
Ako môže byť veľkosť súboru nula?

Video: Ako môže byť veľkosť súboru nula?

Video: Ako môže byť veľkosť súboru nula?
Video: 𝗛𝗼𝗿𝗶𝘇𝗼𝗻 𝗭𝗲𝗿𝗼 𝗗𝗮𝘄𝗻 𝗖𝗼𝗺𝗽𝗹𝗲𝘁𝗲 𝗘𝗱𝗶𝘁𝗶𝗼𝗻 𝗚𝗔𝗠𝗘𝗠𝗢𝗩𝗜𝗘 𝗛𝗗𝗥 𝗦𝗧𝗢𝗥𝗬 𝗔𝗟𝗟 𝗖𝗨𝗧𝗦𝗖𝗘𝗡𝗘𝗦 𝟰𝗸 𝟮𝟭𝟲𝟬𝗽 - YouTube 2024, Apríl
Anonim
Všetci príležitostne narazíme na "situáciu" v našich počítačoch, ktoré nám úplne zmiernia, napríklad súbor, ktorý má veľkosť nuly, ale ako je to možné? Príspevok Q & A SuperUser dnes má odpovede na zmätočnú otázku čitateľa.
Všetci príležitostne narazíme na "situáciu" v našich počítačoch, ktoré nám úplne zmiernia, napríklad súbor, ktorý má veľkosť nuly, ale ako je to možné? Príspevok Q & A SuperUser dnes má odpovede na zmätočnú otázku čitateľa.

Dnešná relácia otázok a odpovedí sa k nám dostala s láskavým združením oddeleniu SuperUser - rozdelenie Stack Exchange, skupiny komunitných skupín otázok a odpovedí.

Otázka

Čítačka SuperUser Eugene S chce vedieť, ako veľkosť súboru môže byť nula:

This is something that I ran into and could not think of a proper explanation. If I create an empty *.txt file on my computer and then look at its size, it shows a size of zero. How is that possible? I mean even if the file itself is empty, it must still have some size (even it if is just to store its own name). How can this be explained?

Ako je možné mať súbor veľkosť nuly?

Odpoveď

Sponzori SuperUser David Schwartz a Cort Ammon majú odpoveď pre nás. Prvýkrát, David Schwartz:

It is possible because there really is no file. There is just a directory entry with a name and owner. The directory entry is logically distinct from the file. For example, the same file can have more than one name in more than one directory.

Unfortunately, the term file is not always used to mean precisely the same thing. But the file size logic comes from the model where a directory entry attaches a file to a directory, then the file names and related meta data are stored in the directory.

Nasledovala odpoveď od Cort Ammon:

The semantic meaning of file size is different from the one you are using.

There are many file sizes which are meaningful. The most common one, and the one you are seeing here, is the number of bytes in the file. If the file is an empty text file, it may indeed contain zero bytes. This number is important to programmers because we often need to open a file, read all the data, and close it. We need to know how many bytes of data will be in the file so we can plan ahead.

Another meaning arises from the way most file systems store data. Most file systems store data in blocks. For example, the file system may store data in 64 kB blocks, meaning it will never allocate anything which is not an even multiple of 64 kB. This sounds inefficient, but it can make bookkeeping quite a bit simpler, and often simpler means faster.

A third meaning, which you are tugging at, would be the actual number of bits required on the hard-drive to describe the presence of a file. This includes information that is usually stored separately from the file. For instance, in Linux, the concept of the file name is stored in the inode for the directory containing the file. [Based on input from other comments, this is (technically) stored in the directory’s data. When I wrote this, I was thinking of the small-directory case. Data smaller than 156 bytes can be stored directly in the inode.] This is not a commonly used meaning because it is terribly hard to determine without knowing the tremendously deep inner workings of your file system (such as accounting for the space needed to store all the permissions on the file). However, if you have a 1,000,000 byte hard-drive and want to know how big of a file can fit on that hard-drive, this will be a very important meaning to you!

Máte niečo doplniť vysvetlenie? Znížte komentáre. Chcete si prečítať viac odpovedí od iných používateľov technológie Stack Exchange? Pozrite sa na celý diskusný príspevok tu.

Odporúča: