Re: Garbage collectable pinned arrays!
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Wed, 13 Feb 2008 11:26:20 -0600
That's not an unusual case. I've already given two examples of APIs
in widespread use which require a buffer to stay in one position
after the initial function call which accepts the pointer.
True, but if you need this, why is the cost of pinning so important?
The cost of GCHandle.Alloc is ~5500 cycles. That means a one time
cost to pin a buffer that lives until the end of the process, if you
do this early in the process you won't suffer from fragmentation of
the gen0 heap as this object will end on the gen2 heap anyway.
That's what I do now.
But doesn't the object need to be moved to end up in gen2 data space? Won't
the pinning reference prevent that?
Also, you keep ignoring my remark that the fact that addresses of
*Large* objects are fixed is a convenience of the current version of
the CLR, nothing stops MS from changing this.
Which is why the OP is asking for a keyword / MSIL flag that will
let the runtime know that the object is intended to be fixed for as
long as it lives. It would be an implementation detail whether the
memory is allocated from the LOH, OLE task allocator, etc, etc. Also I
don't think that sacrificing GC for such objects would
necessarily be a big loss, they either will live to the end of the
process anyway, or they can be explicitly freed.
But , this is what "fixed" is meant for, sure, it's scope is limited
by it's containing function scope, but you can perfectly pin an
object across several unmanaged function calls.
But it needs an "unsafe" block, for no apparent reason.
.
- Follow-Ups:
- Re: Garbage collectable pinned arrays!
- From: Willy Denoyette [MVP]
- Re: Garbage collectable pinned arrays!
- References:
- Re: Garbage collectable pinned arrays!
- From: Jesse McGrew
- Re: Garbage collectable pinned arrays!
- From: Atmapuri
- Re: Garbage collectable pinned arrays!
- From: Willy Denoyette [MVP]
- Re: Garbage collectable pinned arrays!
- From: Ben Voigt [C++ MVP]
- Re: Garbage collectable pinned arrays!
- From: Willy Denoyette [MVP]
- Re: Garbage collectable pinned arrays!
- From: Ben Voigt [C++ MVP]
- Re: Garbage collectable pinned arrays!
- From: Willy Denoyette [MVP]
- Re: Garbage collectable pinned arrays!
- From: Ben Voigt [C++ MVP]
- Re: Garbage collectable pinned arrays!
- From: Willy Denoyette [MVP]
- Re: Garbage collectable pinned arrays!
- Prev by Date: CONVERSION FROM DBF TO XML
- Next by Date: Never Mind, I got it
- Previous by thread: Re: Garbage collectable pinned arrays!
- Next by thread: Re: Garbage collectable pinned arrays!
- Index(es):
Relevant Pages
|