概述
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/java/nutsandbolts/datatypes.html
boolean: The
总是有人争论。确实一个bit可以表明,但是要看其工作原理,如果其工作是按字节处理数据,显然boolean被定义为一个bit会使得处理比较麻烦,因而不妥。
而我看到的中文论坛中顶多讨论到boolean是可以用1个bit表明,但不是被精确定义的到此为止。
但是作为一个要实现的内容,必须要有明确的定义,而这个定义是在JVM或是其他地方?
据搜,定义是在JVM
http://stackoverflow.com/questions/383551/what-is-the-size-of-a-boolean-variable-in-java
这帖有人给出了测量所占mem的程序例子
That suggests that booleans can basically be packed into a byte each by Sun's JVM.
http://www.velocityreviews.com/forums/t364574-size-of-boolean-type.html#6
It is up to the individual JVM implementation. It is possible that
different amounts of memory will be allocated in different situations.
However, the case that is both most interesting and most measurable is a
large boolean[] array.
I've previously measured it as one byte per element, rounded up to a
multiple of 8 and plus 8 bytes per array overhead. However, your mileage
may vary, and if you really need to know you should measure it on the
system you care about.
Patricia
http://www.daniweb.com/forums/thread33136.html#2
boolean: The
boolean
data type has only two possible values:
true
and
false
. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.
总是有人争论。确实一个bit可以表明,但是要看其工作原理,如果其工作是按字节处理数据,显然boolean被定义为一个bit会使得处理比较麻烦,因而不妥。
而我看到的中文论坛中顶多讨论到boolean是可以用1个bit表明,但不是被精确定义的到此为止。
但是作为一个要实现的内容,必须要有明确的定义,而这个定义是在JVM或是其他地方?
据搜,定义是在JVM
http://stackoverflow.com/questions/383551/what-is-the-size-of-a-boolean-variable-in-java
这帖有人给出了测量所占mem的程序例子
That suggests that booleans can basically be packed into a byte each by Sun's JVM.
http://www.velocityreviews.com/forums/t364574-size-of-boolean-type.html#6
It is up to the individual JVM implementation. It is possible that
different amounts of memory will be allocated in different situations.
However, the case that is both most interesting and most measurable is a
large boolean[] array.
I've previously measured it as one byte per element, rounded up to a
multiple of 8 and plus 8 bytes per array overhead. However, your mileage
may vary, and if you really need to know you should measure it on the
system you care about.
Patricia
http://www.daniweb.com/forums/thread33136.html#2
原文地址:http://hi.baidu.com/redareyou/blog/item/649fb9119cc0dfcba7ef3f1b.html
最后
以上就是优雅帽子为你收集整理的关于Java中的boolean类型所占存储空间的全部内容,希望文章能够帮你解决关于Java中的boolean类型所占存储空间所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复