Home All Groups Group Topic Archive Search About

how to get instance id of runtime objects in .NET?

Author
19 Jul 2006 6:52 AM
lyubomirskiy
Hi,

I was wondering if it is possible to obtain instance id of any random
instantiated object during execution of a C# program. I am guessing
that System.Runtime namespace might be used for this, but I have no
clue as to the specifics. I cannot just insert the id field into the
class declaration, I need to be able to work with objects of already
defined classes.

As an alternative to getting instance ids I can also assign my own ids
by storing all newly created objects of all types in a hashtable, but
this would create difficulties if the object supports a nontrivial hash
function and would require chaining etc. So I am hoping to do it simply
with instance ids, if possible.

Thanks ahead of time for replying.

Author
19 Jul 2006 6:57 AM
Lloyd Dupont
Why do you want that?
There is propably a more appropriate solution!

Beside there is no such thing, object memory might get moved around when
there is garbage collection.
It's transparent, every reference is in fact a double pointer.

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
<lyubomirs***@gmail.com> wrote in message
Show quote
news:1153291970.330266.247970@75g2000cwc.googlegroups.com...
> Hi,
>
> I was wondering if it is possible to obtain instance id of any random
> instantiated object during execution of a C# program. I am guessing
> that System.Runtime namespace might be used for this, but I have no
> clue as to the specifics. I cannot just insert the id field into the
> class declaration, I need to be able to work with objects of already
> defined classes.
>
> As an alternative to getting instance ids I can also assign my own ids
> by storing all newly created objects of all types in a hashtable, but
> this would create difficulties if the object supports a nontrivial hash
> function and would require chaining etc. So I am hoping to do it simply
> with instance ids, if possible.
>
> Thanks ahead of time for replying.
>
Author
19 Jul 2006 7:12 AM
lyubomirskiy
I am not interested in memory location, just a unique id for each
existing object on the heap. So you are saying there are no such unique
ids, just memory addresses?

Lloyd Dupont wrote:
Show quote
> Why do you want that?
> There is propably a more appropriate solution!
>
> Beside there is no such thing, object memory might get moved around when
> there is garbage collection.
> It's transparent, every reference is in fact a double pointer.
>
> --
>
Author
19 Jul 2006 8:40 AM
Lloyd Dupont
>I am not interested in memory location, just a unique id for each
> existing object on the heap. So you are saying there are no such unique
> ids, just memory addresses?
>
I am not saying that at all!

I am saying:

1. There are no such thing as a unique ID to identify object.

2. Trying to infer what you were thinking of I thought you thought of
pointer value. Hence my reply about memory which is moved around.


Show quote
> Lloyd Dupont wrote:
>> Why do you want that?
>> There is propably a more appropriate solution!
>>
>> Beside there is no such thing, object memory might get moved around when
>> there is garbage collection.
>> It's transparent, every reference is in fact a double pointer.
>>
>> --
>>
>

AddThis Social Bookmark Button