<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">You’d better use `UnliftedFFITypes` with unsafe FFI calls, since unsafe FFI calls act like fat prim-ops.</div><div class=""><br class=""></div><div class="">GC can happen during safe FFI calls, safe FFI calls are running on other OS threads rather than GHC scheduling threads.</div><div class=""><br class=""></div><div class="">Note: older version of GHCi used to implemented unsafe FFI using safe FFI, there’s an issue about this here: <a href="https://ghc.haskell.org/trac/ghc/ticket/8281" class="">https://ghc.haskell.org/trac/ghc/ticket/8281</a></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 3 Jan 2018, at 10:51 AM, Reiner Pope <<a href="mailto:reiner.pope@gmail.com" class="">reiner.pope@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Haskell-Cafe,<div class=""><br class=""></div><div class="">I understand from <a href="https://mail.haskell.org/pipermail/haskell-cafe/2014-June/114763.html" class="">https://mail.haskell.org/pipermail/haskell-cafe/2014-June/114763.html</a> that it is safe to pass ByteArray# objects to FFI calls, using the UnliftedFFITypes language extension. As I understand it, the implicit guarantee is that the RTS will pin the ByteArray#'s address in memory for the duration of the FFI call -- even if the ByteArray# wasn't allocated pinned.</div><div class=""><br class=""></div><div class="">I'm curious: how does the RTS achieve this "retroactive" pinning? The documentation at <a href="https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC/Pinned" class="">https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC/Pinned</a> suggests that <i class="">all</i> ByteArrays are allocated pinned to account for the possibility that they will in future be passed to the FFI. Is this really the case? This seems like it forces an unreasonably slow allocator on small (say, ~10-byte) ByteArray allocations where the GC's usual bump-pointer allocator might otherwise be preferable.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Reiner</div></div>
_______________________________________________<br class="">Haskell-Cafe mailing list<br class="">To (un)subscribe, modify options or view archives go to:<br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="">Only members subscribed via the mailman list are allowed to post.</div></blockquote></div><br class=""></body></html>