RE: reference to handle / handle to reference

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Chris Lyon [MSFT] (clyon_at_online.microsoft.com)
Date: 01/14/05


Date: Fri, 14 Jan 2005 20:27:52 GMT

As far as I know, there's no conversion between an object reference and an Int32, unless you pin objects using GCHandles and get their associated IntPtrs.

Also, if you're storing references in a Hashtable, then you are affecting the garbage collector by holding references to the objects, so they'll never get collected.

Even if references are stored internally as numbers in a GC table, there's no way for managed code to access it.

Hope that helps
-Chris

--------------------

>
>i'm looking for a possibility in C# to get a unique Int32 handle for an
>object reference. This handle must later (within the same process of course)
>be convertible back to an object reference (call it handle or pointer or
>whatever...).
>at the moment i'm working with a Hashtable Int32 to Object, but i want to
>optimize this. I know it is possible to work with pointers in unsafe code
>blocks, but as far as i know these pointer remain valid only within these
>blocks, or when they are pinned. and i don't want to disturb the garbage
>collector.
>i mean, somehow a reference must be a number anyway, perhaps an index within
>some garbage collector table, or am i wrong?
>
>

-- 
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at 
http://www.microsoft.com/info/cpyright.htm 
Note:  For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.  


Relevant Pages

  • Re: Cobol data protection? Get a dog...
    ... "Parameters specified in the USING phrase of a method Procedure Division ... some of you who are most knowledgable about the standards process. ... dereference a reference (back to the invokers WS or worse back up through the ... I am aware that you can pass an object reference to a method, ...
    (comp.lang.cobol)
  • Re: Q: closing forms
    ... The only real difference between passing by reference and by value takes ... passing the object reference by reference ... If a Is Nothing Then MsgBox("After call using ByRef, ... Private Sub MyProcByReference ...
    (microsoft.public.dotnet.languages.vb)
  • [JavaIDL] Releasing CORBA object references in Java ?
    ... I was thinking that reference counting was the job of GC. ... But here in Java, the introduction of _releaseand _duplicate() is ... Returns a duplicate of this CORBA object reference. ...
    (comp.lang.java.corba)
  • [JavaIDL] Releasing CORBA object references in Java ?
    ... I was thinking that reference counting was the job of GC. ... But here in Java, the introduction of _releaseand _duplicate() is ... Returns a duplicate of this CORBA object reference. ...
    (comp.lang.java.programmer)
  • Re: Anders Hejlsberg comment on immutable objects
    ... >>explicit interface implementation exists is so an interface name can ... I wouldn't cast to an ... >>Improper conversion sounds like a good description, ... > variable as a sort of implicit reference, ...
    (microsoft.public.dotnet.languages.csharp)