aspose file tools*
The moose likes Cattle Drive and the fly likes spaces = memory ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "spaces = memory ??" Watch "spaces = memory ??" New topic
Author

spaces = memory ??

Steven YaegerII
Ranch Hand

Joined: May 31, 2000
Posts: 182
I can't believe I haven't gotten around to asking until now.
After typing a line, and pressing ENTER twice to skip a line, how many bytes of memory does the blank line take up ? I imagine it's worth a character or so ??
Herbert Maosa
Ranch Hand

Joined: May 03, 2000
Posts: 289
I am not quite sure I understand your question.First I dont know in what application you press this ENTER.But if you are asking in relation to Java, then you might want to know that Java represents all characters as 16 bit unicode characters, that is 2 bytes per character.So the Enter key is ofcourse a single character,so it would correspond to two bytes.Pressing it twice would be 4 bytes. I know this might be a loose answer, but may be I have misunderstood your question.You can come again.
Herbert.
Steven YaegerII
Ranch Hand

Joined: May 31, 2000
Posts: 182
Whoops! Guess I should've been more specific. I was talking about when you type a couple lines of code in notepad, skip a line, and resume typing; how much memory does that empty line take up on your hard drive when you save it? I think you probally got it with two bytes. I'll take a guess at two lines:
This is line one. Line two, a blank one, is just under this.

If saved as a text file in notepad (WIN98), line one would equal 124 bytes (the text, plus two bytes for pressing ENTER at the end of the line). Line two would be worth two bytes (pressing ENTER to skip a line). NOTE - don't know if it'll show or not but the cursor that is stuck at the beginning of line one doesn't count.
Herbert Maosa
Ranch Hand

Joined: May 03, 2000
Posts: 289
Steven,
Please note that the fact about two bytes/character I told you about is specific to the way Java represents characters.If you are talking about writing and saving code in NotePad, then I can not commit myself to determine how the characters will be treated.This is because it will depend on how characters are represented in the language used to develop notepad, which I am not aware of.It could be the same,it could not, I can not guarantee.
What I am saying is that if NotePad was written in Java for example, then we will all know that when we save the file, each character will be represented and saved as 2 bytes.But what if NotePad was written Visual Basic ? or C or C++ ? I dont know.
Herbert.
Steven YaegerII
Ranch Hand

Joined: May 31, 2000
Posts: 182
Thanks, Herbert. I was going over the style guide before sending in assignment 1.1 and wondered how much memory a space was worth. I've always wondered from time to time but it was never on my mind to ask until now. Anyhow, I probally have a bit to learn about the style guide; after I tried to apply spacing, my simple program was a scroll. Gotta go post a question about 1.3 .
Thanks again,
This site is a godsend
Fred Abbot
Ranch Hand

Joined: Jun 01, 2000
Posts: 300
java doesnt use any memory for blank space
it just ignores it you can have as much blank space as you like
although blank space in a string will take up memory and when you print thge string you will see the spaces
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20695
    ∞

When you are using the Windows operating systems, every line is terminated with a CR and a LF (ASCII values 13 and 10). Windows stores files as ASCII - 1 byte per character. So every line takes up at least two bytes. Blank lines take up exactly two bytes.
Line's are terminated with a LF on UNIX systems and CR on Mac systems, thus one byte per blank line.
Yes, the style guide sucks up more memory than the popular styles of ten, twenty, thrity years ago (damn, I'm so old!). But back then, storage space (cards, paper tape, etc) was much more precious than it is now. Now, readability and ease of use is far more important.
Java does take up twice as much space for every character, but it you write your files out to an ASCII text file, it goes back to one byte per character.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
 
Don't get me started about those stupid light bulbs.
 
subject: spaces = memory ??