wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes memory and hard disk size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "memory and hard disk size" Watch "memory and hard disk size" New topic
Author

memory and hard disk size

John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
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

Joined: Jun 02, 2003
Posts: 1923

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?


http://home.arcor.de/hirnstrom/bewerbung
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: memory and hard disk size