gpt4 book ai didi

Java BigDecimal 内存使用情况?

转载 作者:IT老高 更新时间:2023-10-28 20:53:13 29 4
gpt4 key购买 nike

是否有估算 BigDecimal 消耗的内存量的指南?

寻找类似的东西guidelines用于估计 String 内存使用情况。

最佳答案

如果您查看 BigDecimal 源代码中的字段,则会发现:

BigDecimal:
long intCompact +8 bytes
int precision +4 bytes
int scale +4 bytes
String stringCache +?
BigInteger intVal +?

BigInteger:
int bitCount +4 bytes
int bitLength +4 bytes
int firstNonzeroIntNum +4 bytes
int lowestSetBit +4 bytes
int signum +4 bytes
int[] mag +?

stringCache 的注释说

Used to store the canonical string representation, if computed.

假设您不调用 .toString(),它将保持零字节。因此 BigDecimal 是 (8+4+4)=16 bytes + BigInteger

BigInteger 本身就是 4+4+4+4+4=20 bytes + mag

20+16 总共 36 个字节加上幅度,这始终是表示完整整数所需的最小位数。对于数字 n,它需要 log2(n) 位,可以将其转换为整数。你应该使用 about:

36 + Ceiling(log2(n)/8.0) bytes

(请注意,这不包括任何其他对象描述符开销,就像您的字符串示例链接那样,但它应该给您一个很好的总体思路。)

关于Java BigDecimal 内存使用情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2501176/

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