[Mono-list] need some help with PInvoke..

David Jeske jeske@chat.net
Thu, 10 Jul 2003 01:35:44 -0700


On Thu, Jul 10, 2003 at 01:22:55AM -0700, David Jeske wrote:
> For example, given this code:
> 
>   unsafe struct DATA {};
> 
>   unsafe class Foo {
>     unsafe DATA *bar;
>   }
> 
> Will the GC have any problems if bar points to unmanaged memory?

BTW, I just found an MSDN page which seems to clarify this issue. (The
text is probably from somewhere in the CLR reference)

  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_A_2.asp

  "Unlike references (values of reference types), pointers are not
  tracked by the garbage collector -- the garbage collector has no
  knowledge of pointers and the data to which they point. For this
  reason a pointer is not permitted to point to a reference or to a
  struct that contains references, and the referent type of a pointer
  must be an unmanaged-type."

Seems clear that a pointer type will be ignored by the garbage
collector.


  "An unmanaged-type is any type that isn't a reference-type and
  doesn't contain reference-type fields at any level of nesting..."

    "Any user-defined struct-type that contains fields of
    unmanaged-types only."

Seems clear that an unsafe struct of only unmanaged types is an
unmanaged type. 

If I'm reading all that correctly, my "DATA*" struct pointer which
points at the unmanaged heap is just fine and dandy.

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net