Re: Garbage collectable pinned arrays!



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.


.



Relevant Pages

  • Re: Garbage collectable pinned arrays!
    ... The cost of GCHandle.Alloc is ~5500 cycles. ... cost to pin a buffer that lives until the end of the process, ... But doesn't the object need to be moved to end up in gen2 data space? ... To find the generation where your object "lives", you'll have to compare it's address with the start address of the generations returned by: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Scott Storch: RIP
    ... Go to page 12, estimated cost of self-suffiency. ... Long Island’s cost of self-sufficiency is high. ... miscellaneous expenses. ... their lives. ...
    (rec.music.hip-hop)
  • Re: Permanent High Gas Prices
    ... Basically what they're saying here is that for many people whose lives ... The guy with the Xebra claimed $12/month for electricity, ... didn't include whatever his cost was for the batteries he was slowly using ... whereas the pre-tax cost of gasoline is just under US$3 per gallon. ...
    (rec.outdoors.rv-travel)
  • Re: Drug Rep Tells All
    ... for  truth and  the susequent well being of human lives. ... So are you suggesting that we shouldn't consider cost when ... Allopathic medicine as practiced by ... mainstream healthcare saves lives almost exclusively during ...
    (misc.health.alternative)
  • Re: Terror Plot Against Synagogues Foiled
    ... innercities by Radical Islam. ... inevitably last for 10 years and cost 1 to 5 million lives in the ... debt but rather have to earn back the trust of their fellow citizens). ...
    (soc.culture.jewish.moderated)