[project @ 2001-08-08 10:50:36 by simonmar]
Had a brainwave on the way to work this morning, and realised that the
garbage collector can handle "pinned objects" as long as they don't
contain any pointers.
This is absolutely ideal for doing temporary allocation in the FFI,
because what we really want to do is allocate a pinned ByteArray and
let the GC clean it up later. So this set of changes adds the
required framework.
There are two new primops:
newPinnedByteArray# :: Int# -> State# s -> (# State# s, MutByteArr# s #)
byteArrayContents# :: ByteArr# -> Addr#
obviously byteArrayContents# is highly unsafe.
Allocating a pinned ByteArr# isn't the default, because a pinned
ByteArr# will hold an entire block (currently 4k) live until it is
garbage collected (that doesn't mean each pinned ByteArr# requires
4k of storage, just that if a block contains a single live pinned
ByteArray, the whole block must be retained).