看到书里有这么一段话:
一个Integer对象会使用24字节,其中分别是:
16字节的对象开销
4字节用于保存它的int值
4个填充字节
我想请教的是:
什么对象开销?16字节里面究竟存储着什么?
填充字节又是什么?它里面存储着什么?
ringa_lee2017-04-18 09:57:50
16 bytes is Object Header
,包括了Mark word
,Class
type information...(16 bytes is the size on 64-bit systems, and pointer compression is not turned on)
HotSpot's alignment is 8-byte alignment. All objects whose final size is not a multiple of 8 bytes will be filled
PHP中文网2017-04-18 09:57:50
The object overhead contains the basic information of the object; the padding bytes are used to fill the number of bytes. The bytes occupied by the object must be a multiple of 8 bytes.
大家讲道理2017-04-18 09:57:50
The following is just an irresponsible guess:
Integer inherits from Object. When constructing Integer, you must first construct Object. The object overhead is the overhead of constructing Object at this time. 8 bytes are empty objects and 4 bytes are object references. , but the byte allocation in Java is in units of 8, so 16 bytes are used here, and the useless bytes are called padding bytes.
The padding bytes below are the same.