V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
varnotfound
V2EX  ›  Java

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

  •  
  •   varnotfound · 2015-09-17 14:20:59 +08:00 · 3431 次点击
    这是一个创建于 3155 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 原理中也没有找到数组存储的最大容量的显式说明,请各位技术大神解惑 :-)
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1848 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 16:38 · PVG 00:38 · LAX 09:38 · JFK 12:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.