#5556: Support pin-changing on ByteArray#s
---------------------------------+------------------------------------------
Reporter: pumpkin | Owner:
Type: feature request | Status: new
Priority: normal | Component: Compiler
Version: 7.2.1 | Keywords:
Testcase: | Blockedby:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
I'm mostly posting this here as a chance for discussion for this feature,
as I've wanted it a few times before and because Roman Leshchinskiy
mentioned it on reddit and reminded me.
<quoting>
IIRC, the basic idea was to have an operation like:
{{{
pin# :: ByteArray# -> ByteArray#
}}}
Then you could say:
{{{
let y = pin# x
}}}
and y would have the same contents as x but be pinned. Whether it is the
same memory block as x would be implementation-dependent but with GHC, it
would be. When GHC would garbage collect y, it would unpin x (if x is
still alive). You would also have unpin# so if you said:
{{{
let z = unpin# y
}}}
then z will become unpinned when y is garbage collected.
</quoting>
I mostly care because it's unfortunate to have to decide up front whether
you want to suffer from memory fragmentation or to support foreign
bindings. This could for example let us break the distinction between
Data.Vector.Unboxed and Data.Vector.Storable. From a higher level, you
might have a `withPinned` function that would temporarily pin (without
copying) an array while you make foreign calls with it (even across
multiple foreign calls), and then would unpin it when you're done.
I'm not sure what this would entail on the actual GC/runtime side of
things, but I figured it'd be worth discussing.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5556>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs