Re: Garbage collectable pinned arrays!



On Feb 12, 3:55 am, "Atmapuri" <janez.makov...@xxxxxxx> wrote:
Hi!

As I understand it, pinning is an attribute of the *reference*, not
the object itself. The object is pinned when there's a pinning
reference to it anywhere on the call stack.

Thus, it doesn't make sense for a pinned object to be garbage
collectible. The object can't be considered garbage anyway while
you're still holding a reference to it, and once you let go of the
last reference, it's no longer pinned.

I don't see why you'd even want it to be collectible, actually. The
point of pinning is to let unmanaged code access the object without
worrying that the GC will move it. But collecting the object and
letting its memory be used for something else is just as dangerous as
moving it!

You are mixing two points:

- reference to unamanged memory, where the word pinned also
means that it won't be collected.
- location of the array in GC (Heap or else).

When the array is pinned it is copied to heap. All I would like
to see is an option to allocate the array on the heap initially.

The array is automatically allocated on the heap once it exceeds
a certain size and thu's becomes "pinned", because the heap is
never compacted and all addresses are absolute.

Really? I thought arrays were always allocated on the heap, like any
other reference type. And why do you say the heap is never compacted?

Jesse
.



Relevant Pages

  • Re: Garbage collectable pinned arrays!
    ... reference to it anywhere on the call stack. ... But collecting the object and ... When the array is pinned it is copied to heap. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Garbage collectable pinned arrays!
    ... to see is an option to allocate the array on the heap initially. ... by putting GC.KeepAliveafter the unmanaged code call. ... The reason for this is that the JIt doesn't know about unmanaged code, as a result he *marks* the reference "ia" as a candidate for collection (signals the GC that the object ia refers to may be collected at the moment of the call. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Garbage collectable pinned arrays!
    ... reference to it anywhere on the call stack. ... But collecting the object and ... When the array is pinned it is copied to heap. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Garbage collectable pinned arrays!
    ... But collecting the object and ... When the array is pinned it is copied to heap. ... compacts the generation containing the array. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Garbage collectable pinned arrays!
    ... reference to it anywhere on the call stack. ... But collecting the object and ... When the array is pinned it is copied to heap. ...
    (microsoft.public.dotnet.languages.csharp)

Loading