识别静态变量的存储位置 [英] identify where the static variables are stored

查看:81
本文介绍了识别静态变量的存储位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

推荐答案

它们存储在一些静态定义的内存块中,该内存块是在加载应用程序时静态保留的。准备好执行;它的大小是运行时系统静态知道的。也就是说,这不是堆栈而不是堆。实现取决于JVM和主机操作系统的实现。



从技术上讲,在某些系统中,堆栈和静态内存共享相同的内存单元,从操作系统的角度来看看来,但在逻辑上/功能上它们仍然是孤立的,所以我在上面的段落中所说的仍然是正确的。同样,实现可能会有所不同,但这个内存的功能属性是相同的。



我不认为你的问题标题中的识别这个词是有道理的。也许您需要了解静态字段属于类本身,而不是属于每个单独的实例。字段的对象每个类只有一个。有时,这些字段称为类字段,而不是实例字段。



现在,如果字段类型是引用类型,显而易见的是,只有引用对象本身存储在静态内存块中,但引用的对象在堆上。在这里,您需要了解任何引用类型的对象由内存中的两个对象表示:引用部分(模拟本机内存系统中的指针)和引用的部分。



-SA
They are stored in some statically defined block of memory statically reserved by the moment when the application is loaded and is ready for execution; it's size is statically known to runtime system. That is, this is not stack and not heap. The implementation depends on the implementation of JVM and host OS.

Technically speaking, in some system, stack and static memory share the same memory unit, from the OS point of view, but logically/functionally they are still isolated, so what I said in the paragraph above is still true. Again, implementations can be different, but functional properties of this memory are the same.

I don't think the word "identify" in your question title makes sense. Perhaps you need to understand that static fields belong to the class itself, not to each individual instance. The object of a field is only one per class. Sometimes, such fields are called "class fields", as opposed to "instance fields".

Now, if a field type is of reference type, it should be obvious that only the reference object itself is stored in the static memory block, but the referenced object is on heap. Here, you need to understand that any object of reference type is represented by two objects in memory: the reference part (analog to pointer in native memory systems) and referenced part.

—SA


Google是你的朋友:好好经常拜访他。他可以比在这里发布问题更快地回答问题...



一次非常快速的搜索给出了近百万次点击:存储静态变量的java程序 - Google搜索 [ ^ ]

最佳答案非常完整: java中存储的静态变量是什么? - 堆栈溢出 [ ^ ]



将来,请尝试自己做至少基础研究,不要浪费你的时间或我们的时间。
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search gave nearly a million hits: java program where the static variables are stored - Google Search[^]
The top answer is pretty complete: Where are static variables stored in java? - Stack Overflow[^]

In future, please try to do at least basic research yourself, and not waste your time or ours.


这篇关于识别静态变量的存储位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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