• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

memory and hard disk size

 
John King
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an ascii file that takes about 100 KB on the hard disk.
How much space would it table if the file is loaded in memory (RAM)?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Takes 100 k, found by du?
Or is it effectively 100 k in size?

I would expect it to take 100 k in the second case.

What do you expect? Why are you asking?
 
Tim Holloway
Saloon Keeper
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a file takes 100,321 bytes on disk and you load it into RAM, it will take 100,321 bytes of RAM. Actual mileage will vary, since there's overhead in both cases - on disk, there's the directory info, and in RAM, there's storage management overhead. But for a file that big, the overhead is comparatively small for most systems both in terms of file overhead and storage overhead, and can thus be ignored. Usually.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afaik, the situation is a bit different.

A file on disk will allways use complete sectors, and the sectorsize may vary.
Thus, a file being 1 or 2 bytes long will use much more space on disk.

A short bash-session:

1. echoing "a" into a file will put a newline ('\n') at the end, leading to two bytes.
2. checking the size with wc (word count) shows: two characters.
3. du (disk usage) reports 4,0 K=4096 bytes. Ooops.
4. stat shows, 8 Blocks are used, (each of 512 Bytes).

A file of 4096 bytes would use the same amount of space on the disk.

Now - does a file need (additional) space for a directory entry?
I 'don't know for other filesystems than mine (reiserfs 3.6) where I can test it; bash-session-2:

1. Checking free diskspace (df).
2. Create an empty file (which needs no space for content)
3. Check free space again

We see: unchanged.
A file of 100 321 bytes would use 102 400 on my disk.

Loading a file to memory can be done in several ways.
I can imagine storing it in a "HashMap <BigInteger, Character>" and would expect that to be a very ram consuming way.
[ May 22, 2007: Message edited by: Stefan Wagner ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic