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

L

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.
 
L

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>
 
L

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?
 
L

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top