1
$\begingroup$

I have this doubt for long time. When i save a notepad file, it takes the memory for the information in the file. let's say, I type 'ABC' in notepad and saved the filename as stack, it shows that the memory consumed 3 bytes for the file but what about the file name " stack" ? Where does it store that particular information in our memory?

$\endgroup$
1
  • 1
    $\begingroup$ Use these keywords file system to search and read about the different ways that this is done. $\endgroup$ – plop Jul 17 '20 at 22:04
1
$\begingroup$

You are right, the computer saves the file name somewhere. But not, it isn't kept in a "stack" or in "memory", files are kept on external memory (disk, flashdrive, perhaps even somewhere else "on the cloud"). This memory in turn is organized to give an efficient map from file names (stored in filesystem proper data structures) to file contents (arranged so it is e.g. possible to extend the file, erase it's contents and reclaim the space, ...). When you ask your operating system for the file size, it answers with the user-visible space (as that is what you presumably are interested in). The space used up in management of the above (file name, references to the pieces used by this file, map of free space on the device, directory structure for managing names, ...) is usually not your concern. You can ask for it if you look at "how full is the device", just that the space used for management usually can't really be associated with a particular file, it is used by many files together.

Get some book on operating systems, and look up "file systems". Or check simple examples like the (MS-DOS) FAT filesystem or the Unix file system design (just concentrate on the Version 7 one, with it's simple layout). File systems in current use are very complex beasts, trying to squeeze out performance of humongous, glacially slow, rotating disks or levelling wear on fast SSDs.

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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