module Data.StorableVector.ST.Private where
import qualified Data.StorableVector.Base as V
import Data.StorableVector.Memory (mallocForeignPtrArray, )
import Control.Monad.ST.Strict (ST, )
import Foreign.Ptr (Ptr, )
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr, )
import Foreign.Storable (Storable, )
import qualified System.Unsafe as Unsafe
import Prelude hiding (read, length, )
data Vector s a =
SV !(ForeignPtr a)
!Int
create :: (Storable a) => Int -> (Ptr a -> IO ()) -> IO (Vector s a)
create l f = do
fp <- mallocForeignPtrArray l
withForeignPtr fp f
return $! SV fp l
unsafeCreate :: (Storable a) => Int -> (Ptr a -> IO ()) -> ST s (Vector s a)
unsafeCreate l f = Unsafe.ioToST $ create l f
unsafeToVector :: Vector s a -> ST s (V.Vector a)
unsafeToVector (SV x l) = return (V.SV x 0 l)