Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

size for data type boolean

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please let me know how much memory size does a boolean type take?
 
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That depends on the JVM.
 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But there must be some range.
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The size of all other primitives in Java are well-defined, but the size of boolean is not. I not aware of any JVM suppliers documenting how they handle booleans. I think it's safe to say that it's most likely between 1 and 32 bits in length, though that probably doesn't help you much. In fact it's probably between 1 and 8 bits: since all JVMs will support the "byte" data type, we know they can reference memory to that granularity.
The fact is, it's not defined. And there is no "sizeof" operator to fall back on ...
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The size of all other primitives in Java are well-defined, but the size of boolean is not. I not aware of any JVM suppliers documenting how they handle booleans. I think it's safe to say that it's most likely between 1 and 32 bits in length, though that probably doesn't help you much. In fact it's probably between 1 and 8 bits: since all JVMs will support the "byte" data type, we know they can reference memory to that granularity.
The fact is, it's not defined. And there is no "sizeof" operator to fall back on ...
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i've heard is that boolean usually takes up 1 byte
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Parth S.:
what i've heard is that boolean usually takes up 1 byte


You are correct, at least as far as the output of a java.util.RandomAccessFile on Windows 2000 using JDK 1.4.2_01. However, in memory the operating system can't work with a discrete piece of information smaller than a word, which in Win2k is 4 bytes. You can use java.util.BitSet to pack a bunch of booleans together, but it seems silly to worry about the storage of a couple of booleans when any non-trivial program will have hundreds of String objects floating around.
 
reply
    Bookmark Topic Watch Topic
  • New Topic