J Collins
J Collins

Reputation: 2170

Is it possible to get equivalent of 'memory address' of .net Object?

We are rolling a custom serialisation tool into our project and are coming across a need to uniquely identify each object by a primitive value type that can be used as a synonym of its 'identity'. The value need have no meaning or organisation, merely that it is unique and persistent at least for the duration of a serialisation routine. Ideally .net would have internally maintained a unique and persistent object ID that we could store as the object's ID. I know every object has a GetHashCode method, but we are not confident in the value's global uniqueness. Another criteria on accessing such an ID is that the method needs to be very efficient.

I have looked at GetHashCode, the garbage collector and marshalling for ideas, haven't come to anything solid yet.

Upvotes: 4

Views: 439

Answers (1)

SLaks
SLaks

Reputation: 887469

You're looking for the ObjectIDGenerator class, which does exactly what you're trying to do.

Upvotes: 4

Related Questions