对象的JVM深度内存大小 [英] JVM deep memory size of an object

查看:98
本文介绍了对象的JVM深度内存大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,众所周知的Instrumentation Java方法无法正确计算对象的深层大小.

as far as I know the well known Instrumentation Java method is unable to correctly calculate the deep size of an object.

是否有可靠的方法可以在JVM上计算对象的正确深度大小?

Is there a reliable way to compute on the JVM the correct deep size of an object?

我正在考虑的用例是固定(或上限)的内存大小数据结构,即缓存.

The use case I'm thinking about is a fixed (or upper bounded) memory size data structure, i.e. a cache.

注意:我尽可能要一种适合企业使用的解决方案,因此是标准"编码实践或经过良好测试的库

Note: as far as possible, I would like an enterprise-ready solution, so either a "standard" coding practice or a well tested library

推荐答案

我知道众所周知的Instrumentation Java方法无法正确计算对象的深层大小.

I know the well known Instrumentation Java method is unable to correctly calculate the deep size of an object.

单独使用仪器,不会.

通过检测和了解特定JVM的内存布局方式,将得出您使用的字节数.它不会告诉您其他JVM可能如何工作,也不会告诉您共享了多少数据.

With instrumentation and a knowledge of how the memory of a particular JVM is laid out will give your number of bytes used. It won't tell you how other JVMs might work and it doesn't tell you how much data is shared.

是否有可靠的方法可以在JVM上计算对象的正确深度大小?

Is there a reliable way to compute on the JVM the correct deep size of an object?

我使用了探查器,但是除非您相信所用的某些工具,否则您永远不会知道.

I use a profiler, but unless you believe some of the tools you use you can never know.

我正在考虑的用例是固定(或上限)的内存大小数据结构,即缓存.

The use case I'm thinking about is a fixed (or upper bounded) memory size data structure, i.e. a cache.

您愿意为精确的内存使用而进行高速缓存吗?如果它的速度慢10倍或100倍,但用法非常准确,这比仅计算元素数量的东西要好吗?

How slow are you willing to make your cache for precise memory usage? If it is 10x or 100x slower but has very accurate usage is this better than something which just counts the number of elements?

因此是标准"编码实践或经过良好测试的库

so either a "standard" coding practice or a well tested library

在这种情况下,请使用元素计数.您可以为此使用LinkedHashMap或ehcache.

In that case, use the element count. You can use LinkedHashMap or ehcache for this.

这篇关于对象的JVM深度内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆