我有一个 Map(String, String) ,我想求出一个 Entry 和 Map 总共的内存大小。我在某处读到 Instrumentation 可能有用 ( Instrumentation )。有人有想法吗?
提前致谢。
最佳答案
java.util.AbstractMap.SimpleEntry
的空白实例对于 64 位 JVM 应该是 24 字节,对于 32 位 JVM 应该是 12 字节。这是我发现有用的@PeterLawrey 技术,基于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());
关于java - 计算 Map Entry 的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20458456/