如何计算java数组内存使用量 [英] how calculate java array memory usage

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

问题描述

如果我有:

int c[] = new int[10];

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

一般来说

一个 n*m*..*j 数组

如何同时考虑引用变量来计算实际内存使用量?

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天全站免登陆