Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

memory and hard disk size

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 25466
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
That new kid is a freak. Show him this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic