通过哈希码从内存中获取对象 [英] get object from memory by hash code

查看:261
本文介绍了通过哈希码从内存中获取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我在想。我在执行环境One中创建了一个A类对象。并从此处获取该对象的哈希码。

Today i was thinking. I create an object of class A in an execution environment One. And get the hash code from here of that object.

我认为这是可能的。因为当我执行环境时。我一次又一次地得到JVM返回相同的哈希码。

I think it is possible. Because when I execute environment one. Again and again i get that JVM return the same hash code.

表示它首先在缓存中找到对象。如果得到参考,它就会返回它。

Means it first find the object in its cache. If it get the reference, it just return it.

现在回过头来看,我们必须要了解哪些数据是当我们
写=时复制。

So now back to question, we have to understand what data is copied when we write =.

  Object a=new Object();// here as we know reference of new object will be stored in refvar a.

然后实际经过的是什么。

Then what in actual is passes through.

如果我们得到=(等于运算符)传递的数据。我们将能够从内存中获取对象。

If we get what data is passed by =(equal operator). We will able to get the object from memory.

谢谢

推荐答案


我们如何通过证明哈希码来从内存中获取对象?

How we can we get the object from memory by proving hash code?

你不能没有访问JVM的内部。即便如此,您仍需要扫描内存中的每个对象。除了具有相同hashCode的多个对象之外,您还会遇到此问题。 BTW:默认情况下,对象在你要求之前没有hashCode。

You can't without access to the internals of the JVM. Even then you would need to scan every object in memory. You would also have the problem than multiple objects with the same hashCode. BTW: By default objects don't have a hashCode until you ask for one.


我认为这是可能的。因为当我执行环境时。我一次又一次得到JVM返回相同的哈希码。

I think it is possible. Because when I execute environment one. Again and again i get that JVM return the same hash code.

这只能用于重新创建hashCode为的确切条件生成,最轻微的更改,你会得到不同的hashCodes。

This only works because you are recreating the exact conditions where the hashCode as generated, the slightest changes and you would get different hashCodes.


意味着它首先在其缓存中找到对象。如果它得到参考,它只是返回它。

Means it first find the object in its cache. If it get the reference, it just return it.

你表示你需要维护的缓存,JVM中不存在这样的缓存。

By it you mean a cache you would need to maintain, no such cache exists in the JVM.


所以现在回过头来看,我们必须明白什么当我们写=时,数据被复制。

So now back to question, we have to understand what data is copied when we write =.

Object a=new Object();// here as we know reference of new object will be stored in refvar a.

然后实际通过的是什么。

Then what in actual is passes through.

如你所说,引用已通过。没别了。

The reference is passed, like you said. Nothing else.

这篇关于通过哈希码从内存中获取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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