关于Java中的boolean类型所占存储空间
2011-03-20 00:36
204 查看
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
There is no need to know. A boolean is a boolean is a boolean. How it's defined internally is inconsequential to the person using the datatype.
It could even be different on different JVMs, so counting on a particular implementation is dangerous.
这位则说,内部如何定义不重要,刻意计算其占容反而会因为在不同JVM中定义不同而变得不安全。
http://forums.sun.com/thread.jspa?threadID=5434070 SIZE of Boolean
打开sun的JVM库的boolean,也看不懂也看不出哪里有写了占有多少内存。
原文地址:http://hi.baidu.com/redareyou/blog/item/649fb9119cc0dfcba7ef3f1b.html
boolean: The
booleandata type has only two possible values:
trueand
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
There is no need to know. A boolean is a boolean is a boolean. How it's defined internally is inconsequential to the person using the datatype.
It could even be different on different JVMs, so counting on a particular implementation is dangerous.
这位则说,内部如何定义不重要,刻意计算其占容反而会因为在不同JVM中定义不同而变得不安全。
http://forums.sun.com/thread.jspa?threadID=5434070 SIZE of Boolean
打开sun的JVM库的boolean,也看不懂也看不出哪里有写了占有多少内存。
原文地址:http://hi.baidu.com/redareyou/blog/item/649fb9119cc0dfcba7ef3f1b.html
相关文章推荐
- java中关于String 类型数据 的存储方式
- Java中的存储空间类型
- 关于javaBean中boolean类型变量的set和get
- java中关于String 类型数据 的存储方式
- Java 入门 之 数据类型与存储空间
- 浅谈Java中的存储空间类型
- Java中使用Hibernate存储Date类型及Boolean类型到Orcale数据库中的心得
- Java-基本数据类型所占存储空间
- 关于javaBean中boolean类型变量的set和get注入后传到前端JS中的问题
- 当java调用oracle的存储过程时,存储过程的返回值类型不能为boolean
- 关于Boolean类型在flex与java中间传递的问题
- 浅谈Java中的存储空间类型
- 关于java的data类型向mysql的datetime中存储的问题
- 关于Boolean类型在flex与java中间传递的问题
- 关于Java中基本类型的存储位置
- 关于Boolean类型在flex与java中间传递的问题
- Java中使用Hibernate存储Date类型及Boolean类型到Orcale数据库中的心得
- JAVA基础-数据类型及基本数据类型的存储空间
- 关于java基础类型与引用类型内存存储问题,以及string.intern()方法(String两种创建方式的区别)
- 浅谈Java中的存储空间类型