gpt4 book ai didi

java - Java 在内存(或其他地方)中如何表示对象的结尾?

转载 作者:行者123 更新时间:2023-11-30 07:04:42 27 4
gpt4 key购买 nike

比如你创建了两个对象

Circle circle1 = new Circle();
Circle circle2 = new Circle();

我了解到circle1(还有circle2)指向堆上内存中对象的起始位置。但是现在问题来了,它怎么知道什么时候结束?

我唯一能想到的是每个类都等于一个新声明的类型,Java 将每个类型占用的空间存储在其他地方,这样它就知道 circle1 等于内存中的 20 个字节。这样它就神奇地无法改变 circle2 的那个点后面的任何东西。这只是我的想象,希望能找到真正的答案。

最佳答案

对象在 JVM 堆中的表示取决于以下引自 this link 中提到的实现其中描述了 JVM 的结构:

The Java Virtual Machine assumes no particular type of automatic storage management system, and the storage management technique may be chosen according to the implementor's system requirements

同样来自该链接:

2.7. Representation of Objects

The Java Virtual Machine does not mandate any particular internal structure for objects.

In some of Oracle’s implementations of the Java Virtual Machine, a reference to a class instance is a pointer to a handle that is itself a pair of pointers: one to a table containing the methods of the object and a pointer to the Class object that represents the type of the object, and the other to the memory allocated from the heap for the object data.

关于java - Java 在内存(或其他地方)中如何表示对象的结尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27374578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com