对象标识 [英] Object identity

查看:85
本文介绍了对象标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我是.NET的新手,我想知道是否有像

身份价值的东西。一个对象。我的意思是类似于C ++或C中对象的地址

,即每个对象的固定唯一值,可以使用例如

将对象放在关联中容器(哈希值不是

替代品,因为它在对象的生命周期内没有修复)。

我知道垃圾收集器会移动对象内存,所以

不能使用gc指针(至少只要它不是固定)。

有什么像.NET中的固定指针吗?


Thx&问候,


Stephan

解决方案

object.GetHashCode() -

作为特定类型的哈希函数,适用于

哈希

算法和数据结构,如哈希表


-

Vadym Stetsyak又名Vadmyst
http: //vadmyst.blogspot.com


" Stephan Keil" <圣********** @ gmx.de>在消息中写道

新闻:uJ ************* @ TK2MSFTNGP11.phx.gbl ...

大家好,

我是.NET的新手,我想知道是否有像
身份价值这样的东西。一个对象。我的意思是类似于C ++或C中对象的地址,即每个对象的固定唯一值,可用于例如将对象放入关联容器中(哈希值不是
替代,因为它在对象的生命周期内没有被修复。
我知道垃圾收集器在内存中移动对象,所以gc指针不能被使用(在至少只要它不被固定)。在.NET中是否有类似固定指针的东西?

Thx&问候,

Stephan





嗨Stephan,


不,因为你无法控制堆上创建对象的位置,所以你不能得到它的地址。我们使用(不一定用于数据库映射)

IdentityField( http://www.martinfowler.com/eaaCatal...tityField.html

模式。


祝你好运,< br $> b $ b Paul Gielens


访问我的博客@ http://weblogs.asp.net/pgielens/

###


斯蒂芬,

ie每个对象固定的唯一值,可用于例如将对象放入关联容器中


你不能存储对象引用本身吗?


我知道垃圾收集器会在内存中移动对象,所以gc指针不能被使用(至少只要它不是固定)。



当发生这种情况时,所有参考资料都会更新。

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http: //www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。


Hi all,

I am a novice with .NET and I am wondering if there is something like an
"identity value" of an object. I mean something like the object''s address
in C++ or C, i.e. a fixed unique value per object, which can be used e.g.
to put objects in an associative container (a hash value is not an
alternative as it is not fixed during the object''s life time).
I know that the garbage collector moves objects around in the memory, so
the gc pointer cannot be used (at least as long as it is not "pinned"). Is
there anything like a fixed pointer in .NET?

Thx & regards,

Stephan

解决方案

object.GetHashCode() -
"serves as a hash function for a particular type, suitable for use in
hashing
algorithms and data structures like a hash table"

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"Stephan Keil" <St**********@gmx.de> wrote in message
news:uJ*************@TK2MSFTNGP11.phx.gbl...

Hi all,

I am a novice with .NET and I am wondering if there is something like an
"identity value" of an object. I mean something like the object''s address
in C++ or C, i.e. a fixed unique value per object, which can be used e.g.
to put objects in an associative container (a hash value is not an
alternative as it is not fixed during the object''s life time).
I know that the garbage collector moves objects around in the memory, so
the gc pointer cannot be used (at least as long as it is not "pinned"). Is
there anything like a fixed pointer in .NET?

Thx & regards,

Stephan




Hi Stephan,

No, since you have no control where on the heap an object is created, you
can''t get its address. We use (not necessarily for database mapping) the
IdentityField (http://www.martinfowler.com/eaaCatal...tityField.html)
pattern.

Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/
###


Stephan,

i.e. a fixed unique value per object, which can be used e.g.
to put objects in an associative container
Can''t you store the object reference itself?

I know that the garbage collector moves objects around in the memory, so
the gc pointer cannot be used (at least as long as it is not "pinned").



When that happens all references are updated.
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


这篇关于对象标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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