java - 整数的封装对象中的对象开销和填充字节是什么东东
PHP中文网
PHP中文网 2017-04-18 09:55:50
0
3
400

看到书里有这么一段话:
一个Integer对象会使用24字节,其中分别是:

  • 16字节的对象开销

  • 4字节用于保存它的int值

  • 4个填充字节

我想请教的是:

  • 什么对象开销?16字节里面究竟存储着什么?

  • 填充字节又是什么?它里面存储着什么?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
左手右手慢动作
  1. 16 bytes is Object Header,包括了Mark word,Classtype information...(16 bytes is the size on 64-bit systems, and pointer compression is not turned on)

  2. HotSpot's alignment is 8-byte alignment. All objects whose final size is not a multiple of 8 bytes will be filled

Ty80

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.

大家讲道理

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!