如何计算Java数组的内存使用情况 [英] how calculate java array memory usage

查看:104
本文介绍了如何计算Java数组的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有:

int c[] = new int[10];

int a[][] = new int[2][3];

和一般在

N * M *。*Ĵ阵列

我怎么能计算出的实际内存使用率也在考虑引用变量?

how can I calculate the real memory usage considering also the references variables?

推荐答案

如果你想要一个准确的答案,你不能。至少不以任​​何简便的方法。 这个线程详细解释。

If you want an accurate answer, you can't. At least not in any easy way. This thread explains more.

与Bragaadeesh的和Bakkal的回答麻烦的是,他们忽略的开销。每个阵列还存储之类的东西的尺寸拥有的数量,它有多长,有些东西的垃圾收集器使用。

The trouble with Bragaadeesh's and Bakkal's answers are that they ignore overhead. Each array also stores things like the number of dimensions it has, how long it is and some stuff the garbage collector uses.

对于一个简单的估算,应使用来自其他答案计算和添加100-200字节被罚款。

For a simple estimate, you should be fine by using the calculations from the other answers and adding 100-200 bytes.

这篇关于如何计算Java数组的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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