Last active
December 18, 2015 23:09
-
-
Save rblaze/5859979 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
saveVector :: String -> Vector a -> IO () | |
saveVector name vec = | |
withFile name WriteMode $ \h -> do | |
let (ptr, len) = U.unsafeToForeignPtr0 vec | |
withForeignPtr ptr $ \p -> hPutBuf h p (len * sizeOf (0 :: a)) | |
loadVector :: String -> IO Vector a | |
loadVector name = | |
withFile name ReadMode $ \h -> do | |
len <- liftM fromIntegral $ hFileSize h | |
ptr <- mallocForeignPtrBytes len | |
_ <- withForeignPtr ptr $ \p -> hGetBuf h p len | |
return $ U.unsafeFromForeignPtr0 ptr (len `div` sizeof (0 :: a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment