• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

memory and hard disk size

 
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)?
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • 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?
 
Saloon Keeper
Posts: 22779
153
Android Eclipse IDE Tomcat Server Redhat Java 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
Scala Postgres Database Linux
  • 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 ]
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic