Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String and boolean memory

 
Amr Khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1) How do I know that the String text below occupies how much memory?
String text=" My name is Tom. ";
Q2) What is the memory occupied by a boolean?

 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you actuallu meant memory, I don't know how much or why you would need to know it anyway. As for size, use the length() method on the string. I believe a boolean is 1 bit in size.

Bosun
 
Jason Ford
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, a boolean is probably stored as a byte. Though this is an inefficient use of memory, the complications involved in addressing a single bit of memory more than justify this implementation.
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe each character in a String uses two bytes of memory, even whitespace characters.
 
Noorulain Khan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
String:
is a Non-primitive data type and in actual is array.
Array is like we stack stuff somewhere with Last in First Out method. Likewise the data is stored in memory with the same method Byte by Byte. Therefore the size will vary depending upon the characters are given in a string.
However if you would want to know about the size of the string variable (veryuseful in programming as well) you can use
length() method.
Boolean:
In java the length and code both are not described anywhere and
at all.
But through studies i guess it occupies the least memory of rest of the datatypes.
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic