#Size of a boolean

1 messages · Page 1 of 1 (latest)

green spruce
#

Studying a bit for ocp17 and now I have a question about a boolean that I haven't really thought about before. Maybe I'm reading it wrong,

They say that the bit size of a boolean depends on the JVM. This would mean that the binary representation of a class containing a boolean would have different magnitudes on different machines

what is your thoughts on this?

sterile yarrowBOT
#

<@&987246399047479336> please have a look, thanks.

sterile yarrowBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If your code is long, or you have multiple files to share, consider posting it on sites like https://pastebin.com/ and share the link instead, that is easier to browse for helpers.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

midnight ether
#

I don't see this as a problem in any way. The jvm uses the size best suited for the system it's running on. Nobody should be touching the raw data of an object, and if they are using Unsafe for that they should also use it to get the runtime offset

green spruce
#

i dont say its a problem. i just wanna know the filosofie behind it

midnight ether
#

Well, it's easy to leave this as an implementation detail as nobody should ever interact with it. Why add a spec for something that doesn't need it.

green spruce
#

nahh its easy to just say "its best suited" i want to know why its best suited and on what factors. Thought mayby someone here knows

neat wedge
#

even int

#

nothing in the jls says that an int must be implemented with 32bits

#

it's entirely up to the jvm

midnight ether
neat wedge
#

exactly

#

but whether the jvm wants to use more or less bits for it, is up to the jvm

#

which gives it enough freedom to do tricks and optimizations

#

such as padding or compression

green spruce
#

that's right indeed, thought maybe it's something else since boolean was mentioned so explicitly in the textbook

#

thanks!