varnotfound
V2EX  ›  Java

ArrayList 的最大长度为什么是 int 最大值减 8,不懂这 8 个长度去做什么了

  •  
  •   varnotfound · Sep 17, 2015 · 4315 views
    This topic created in 3896 days ago, the information mentioned may be changed or developed.

    ArrayList 使用数组来存储数据,数组的下标为 int 型。在 ArrayList 的源码中定义的存储数组下标最大值为:

    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;

    不明白这减个 8 是用来存储什么的?注释” Some VMs reserve some header words in an array “ 没懂这指的是什么? jvm 原理中也没有找到数组存储的最大容量的显式说明,请各位技术大神解惑 :-)
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5892 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:09 · PVG 15:09 · LAX 00:09 · JFK 03:09
    ♥ Do have faith in what you're doing.