Java方法的内存开销是多少? [英] What is the memory overhead of a Java method?

查看:211
本文介绍了Java方法的内存开销是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类中函数的内存开销是多少?

What is the memory overhead of a function in a class?

例如,

Class A
{
 int a
}

Class B
{
 int a
 int foo(int);
}

因此,A类的100个实例应该是80个字节。怎么样的B类100个实例?

So 100 instances of class A should be 80 bytes. What about 100 instances of class B?

推荐答案

开销是......无。

The overhead is... none.

方法定义和代码地址存储在Class对象中,该对象具有一个唯一的实例,对象的每个实例都指向该实例。
既然如此,无论你是否添加了这个方法,每个单独对象的开销都是空的。

The method definition and code address are stored in the Class object, which has a unique instance toward which every instance of your object points. Since that would be the case, whether or not you added that method, the overhead for each individual object is nothing.

这篇关于Java方法的内存开销是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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