哪里的方法存储在内存中? [英] Where are methods stored in memory?

查看:302
本文介绍了哪里的方法存储在内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到,类字段存储在堆中,哪来的方法存储在哪里?在堆或其他地方?他们是内联?

I learned that class fields are stored in the heap, but where are methods stored? In the heap or somewhere else? are they inline?

推荐答案

方法都存在别处在内存中。请注意,方法是每一个类,而不是每个实例。因此通常,方法的数目超过一个程序的运行时不改变(也有例外)。在传统的模式,这里的方法居住的地方被称为code段。在.NET中,这是比较难:该方法最初住在组装,并获得映射到进程的内存。在那里,刚刚即时编译器创建的本地code一些方法的第二个副本;这个副本被执行。在JIT code可能会建立和运行过程中删除了好几次,所以这是可行的,在堆也认为这是生活。

Methods are stored somewhere else in the memory. Notice that methods are per-class, not per-instance. So typically, the number of methods doesn't change over the run-time of a program (there are exceptions). In traditional models, the place where the methods live is called the "code segment". In .net, it's more difficult: the methods originally live in the assembly, and get mapped into the process memory. There, the just-in-time compiler creates a second copy of some methods in native code; this copy gets executed. The JIT code may get created and deleted several times during the runtime, so it is practical to view it also as living "in Heap".

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

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