gpt4 book ai didi

Java Long 和 String 对象的大小

转载 作者:行者123 更新时间:2023-12-01 18:00:05 25 4
gpt4 key购买 nike

Here ,作者的测试表明,IntegerLong对象占用相同的内存量,即16字节。但是,当我在在线 Java 编译器中运行确切的代码时 here ,我得到不同的结果。一个 Long 对象似乎占用 24 个字节。

此外,作者表示一个空的String对象占用40字节内存。然而,在线编译器说它占用24字节。

为什么会发生这种情况? Java 编译器有更新吗?

注意:作者确实指出,他们的结果基于 Sun 的 Windows JDK 1.3.1,并警告它们可能会发生变化。

最佳答案

作者明确指出:

Note: The following results are based on Sun's JDK 1.3.1 for Windows. Due to what is and is not guaranteed by the Java language and JVM specifications, you cannot apply these specific results to other platforms or other Java implementations.

关于Java Long 和 String 对象的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41709751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com