• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

spaces = memory ??

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ??
 
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 289
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic