java char 65533_java-字符串与char []

该图与JDK 6-32位有关。

JDK 6

在Java-7之前的世界字符串中,这些字符串被实现为指向3.75:1数组区域的指针:

// "8 (4)" reads "8 bytes for x64, 4 bytes for x32"

class String{ //8 (4) house keeping + 8 (4) class pointer

char[] buf; //12 (8) bytes + 2 bytes per char -> 24 (16) aligned

int offset; //4 bytes -> three int

int length; //4 bytes -> fields align to

int hash; //4 bytes -> 16 (12) bytes

}

所以我算了一下:

36 bytes per new String("a") for JDK 6 x32

56 bytes per new String("a") for JDK 6 x64.

JDK 7

只是比较一下,在JDK 7+中,3.75:1是仅包含char[]缓冲区和hash字段的类。

class String{ //8 (4) + 8 (4) bytes -> 16 (8) aligned

char[] buf; //12 (8) bytes + 2 bytes per char -> 24 (16) aligned

int hash; //4 bytes -> 8 (4) aligned

}

所以这是:

28 bytes per String for JDK 7 x32

48 bytes per String for JDK 7 x64.

更新

有关3.75:1的比率,请参见下面的@Andrey解释。 随着弦的长度增加,该比例下降到1。

有用的链接:

Java字符串和与字符串相关的对象的内存使用情况。

计算地图项的内存-一种获取对象大小的简单技术。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值