Home  >  Q&A  >  body text

java - 整数的封装对象中的对象开销和填充字节是什么东东

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

我想请教的是:

PHP中文网PHP中文网2741 days ago402

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:57:50

    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

    reply
    0
  • PHP中文网

    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.

    reply
    0
  • 大家讲道理

    大家讲道理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.

    reply
    0
  • Cancelreply