Last active
May 30, 2018 01:28
-
-
Save jchia/40ee37ed760cca87babed902950051ed to your computer and use it in GitHub Desktop.
Copy from UArray to ByteString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import import Data.Array.Base | |
import Data.ByteString | |
import GHC.Prim | |
type Chunk = UArray Int Word8 | |
-- Is there anything preventing byteArray from being relocated by the garbage collector after it's read but before it's used packCStringLen, so that packCStringLen uses an old, invalid, address? | |
chunkToBs :: Chunk -> ByteString | |
chunkToBs (UArray _ _ n byteArray) = unsafePerformIO $ | |
packCStringLen (Ptr (byteArrayContents# byteArray), n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment