计算地图条目的内存 [英] Calculate memory of a Map Entry

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

问题描述

我有一个Map(String,String),我想要找到一个Entry和Map的内存大小。我阅读了Instrumentation可能有用的地方( Instrumentation )。有没有人有想法?



提前感谢。

解决方案

java.util.AbstractMap.SimpleEntry 的空白实例应该64位JVM为24字节,32位JVM为12字节。这是一个@PeterLawrey的技术,我发现有用的,基于 MemoryUsageExamplesTest

  System.out.printf(简单条目使用的平均内存是%.1f字节%n,新的SizeofUtil(){
@Override
protected int create(){
Map.Entry< String,String> e = new AbstractMap.SimpleEntry< String,String>(null,null);
return 1;
}
} .averageBytes());


I have a Map(String, String) and I want to find the memory size of an Entry and the Map in total. I read somewhere that Instrumentation might be useful (Instrumentation). Does anyone have an idea?

Thanks in advance.

解决方案

A blank instance of java.util.AbstractMap.SimpleEntry should be 24 bytes for 64-bit JVM and 12 bytes for 32-bit JVM. Here is a technique by @PeterLawrey I found useful, based on MemoryUsageExamplesTest:

System.out.printf("The average memory used by simple entry is %.1f bytes%n", new SizeofUtil() {
    @Override
    protected int create() {
        Map.Entry<String, String> e = new AbstractMap.SimpleEntry<String, String>(null, null);
        return 1;
    }
}.averageBytes());

这篇关于计算地图条目的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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