on master help sign in
Rename and move unboxed array APIs

Added Unboxed.newUnpinnedBytes and Mut.Type.newUnpinned Array.Unboxed.Mut.Type.nilArrayContents -> Unboxed.nil Array.Unboxed.Mut.Type.newAlignedArrayContents -> Unboxed.newAlignedPinnedBytes Mut.Type: newArray -> newPinned newArrayAligned -> newAlignedPinned Unboxed: newUnpinnedArrayContents -> newUnpinnedBytes

commitba01fcd958da9e25d33160be2c6ec70a82873219 authorAdithya Kumar <adithya@composewell.com> dateMon 3 Oct 2022, 18:24 (4 years ago) parent83ed976
14 files changed+109−93
core/src/Streamly/Data/Array/Unboxed/Mut.hs+2−1 core/src/Streamly/Internal/Data/Array/Unboxed.hs+1−1 core/src/Streamly/Internal/Data/Array/Unboxed/Mut/Type.hs+65−68 core/src/Streamly/Internal/Data/Array/Unboxed/Stream.hs+3−3 core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+3−2 core/src/Streamly/Internal/Data/Fold.hs+1−1 core/src/Streamly/Internal/Data/IORef/Unboxed.hs+2−2 core/src/Streamly/Internal/Data/Ring/Unboxed.hs+1−1 core/src/Streamly/Internal/Data/Unboxed.hs+23−6 core/src/Streamly/Internal/FileSystem/Handle.hs+1−1 src/Streamly/Internal/FileSystem/FD.hs+2−2 src/Streamly/Internal/Network/Socket.hs+2−2 test/Streamly/Test/Data/Array/Unboxed.hs+2−2 test/Streamly/Test/Data/Array/Unboxed/Mut.hs+1−1
core/src/Streamly/Data/Array/Unboxed/Mut.hs+2−1
@@ -19,7 +19,8 @@ module Streamly.Data.Array.Unboxed.Mut
1919 -- ** Construction
2020
2121 -- Uninitialized Arrays
22− , newArray
22+ , new
23+ , newPinned
2324
2425 -- From containers
2526 , fromListN
core/src/Streamly/Internal/Data/Array/Unboxed.hs+1−1
@@ -284,7 +284,7 @@ writeLastN n
284284 in fmap f $ liftIO $ RB.new n
285285
286286 done (Tuple3Fused' rb rh i) = do
287− arr <- liftIO $ MA.newArray n
287+ arr <- liftIO $ MA.newPinned n
288288 foldFunc i rh snoc' arr rb
289289
290290 -- XXX We should write a read unfold for ring.
core/src/Streamly/Internal/Data/Array/Unboxed/Mut/Type.hs+65−68
@@ -18,7 +18,6 @@ module Streamly.Internal.Data.Array.Unboxed.Mut.Type
1818 -- $arrayNotes
1919 Array (..)
2020 , MutableByteArray
21− , nilArrayContents
2221 , touch
2322 , pin
2423 , unpin
@@ -28,11 +27,11 @@ module Streamly.Internal.Data.Array.Unboxed.Mut.Type
2827 , nil
2928
3029 -- *** Uninitialized Arrays
31− , newArray
32− , newPinnedArrayBytes
33− , newArrayAligned
30+ , newPinned
31+ , newPinnedBytes
32+ , newAlignedPinned
33+ , new
3434 , newArrayWith
35− , newAlignedArrayContents
3635
3736 -- *** Initialized Arrays
3837 , withNewArrayUnsafe
@@ -234,9 +233,11 @@ import Streamly.Internal.Data.Unboxed
234233 , touch
235234 )
236235import GHC.Base
237− ( IO(..), byteArrayContents#
238− , Int(..), newAlignedPinnedByteArray#
239− , copyMutableByteArray#, compareByteArrays#
236+ ( IO(..)
237+ , Int(..)
238+ , byteArrayContents#
239+ , compareByteArrays#
240+ , copyMutableByteArray#
240241 )
241242import GHC.Base (noinline)
242243import GHC.Exts (unsafeCoerce#)
@@ -248,7 +249,6 @@ import Streamly.Internal.Data.Stream.Type (Stream)
248249import Streamly.Internal.Data.SVar.Type (adaptState, defState)
249250import Streamly.Internal.Data.Unfold.Type (Unfold(..))
250251import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
251−import System.IO.Unsafe (unsafePerformIO)
252252
253253import qualified Streamly.Internal.Data.Fold.Type as FL
254254import qualified Streamly.Internal.Data.Producer as Producer
@@ -385,6 +385,8 @@ unpin arr@Array{..} = do
385385-- Alignment must be greater than or equal to machine word size and a power of
386386-- 2.
387387--
388+-- Alignment is ignored if the allocator allocates unpinned memory.
389+--
388390-- /Pre-release/
389391{-# INLINE newArrayWith #-}
390392newArrayWith :: forall m a. (MonadIO m, Unboxed a)
@@ -399,61 +401,25 @@ newArrayWith alloc alignSize count = do
399401 , arrBound = size
400402 }
401403
402−-- XXX Move this to Unboxed and rename this to newPinnedAlignedBytes?
403−-- XXX Similarly have newUnpinnedBytes
404−{-# INLINE newAlignedArrayContents #-}
405−newAlignedArrayContents :: Int -> Int -> IO (MutableByteArray a)
406−newAlignedArrayContents nbytes _align | nbytes < 0 =
407− errorWithoutStackTrace "newAlignedArrayContents: size must be >= 0"
408−newAlignedArrayContents (I# nbytes) (I# align) = IO $ \s ->
409− case newAlignedPinnedByteArray# nbytes align s of
410− (# s', mbarr# #) ->
411− let c = MutableByteArray mbarr#
412− in (# s', c #)
413−
414−{-# NOINLINE nilArrayContents #-}
415−nilArrayContents :: MutableByteArray a
416−nilArrayContents =
417− unsafePerformIO $ newAlignedArrayContents 0 0
418−
419404nil ::
420405#ifdef DEVBUILD
421406 Unboxed a =>
422407#endif
423408 Array a
424−nil = Array nilArrayContents 0 0 0
425−
426−-- | Like 'newArrayWith' but using an allocator that aligns the memory to the
427−-- alignment dictated by the 'Unboxed' instance of the type.
428−--
429−-- /Internal/
430−{-# INLINE newArrayAligned #-}
431−newArrayAligned :: (MonadIO m, Unboxed a) => Int -> Int -> m (Array a)
432−newArrayAligned = newArrayWith (\s a -> liftIO $ newAlignedArrayContents s a)
409+nil = Array Unboxed.nil 0 0 0
433410
434−-- XXX Intead of newArray, make newPinnedArray and newUnpinnedArray. Make it
435−-- more explicit.
436−-- XXX can unaligned allocation be more efficient when alignment is not needed?
437−--
438−-- | Allocates an empty array that can hold 'count' items. The memory of the
439−-- array is uninitialized and the allocation is aligned as per the 'Unboxed'
440−-- instance of the type.
441−--
442−-- /Pre-release/
443−{-# INLINE newArray #-}
444−newArray :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
445−newArray = newArrayAligned (alignment (undefined :: a))
446411
447412-- | Allocates a pinned empty array that can hold 'count' items. The memory of
448413-- the array is uninitialized and the allocation is aligned as per the
449414-- 'Unboxed' instance of the type.
450415--
451416-- /Pre-release/
452−{-# INLINE newPinnedArrayBytes #-}
453−newPinnedArrayBytes :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
454−newPinnedArrayBytes bytes = do
417+{-# INLINE newPinnedBytes #-}
418+newPinnedBytes :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
419+newPinnedBytes bytes = do
455420 contents <-
456− liftIO $ newAlignedArrayContents bytes (alignment (undefined :: a))
421+ liftIO
422+ $ Unboxed.newAlignedPinnedBytes bytes (alignment (undefined :: a))
457423 return $ Array
458424 { arrContents = contents
459425 , arrStart = 0
@@ -461,6 +427,37 @@ newPinnedArrayBytes bytes = do
461427 , arrBound = bytes
462428 }
463429
430+-- | Like 'newArrayWith' but using an allocator is a pinned memory allocator and
431+-- the alignment is dictated by the 'Unboxed' instance of the type.
432+--
433+-- /Internal/
434+{-# INLINE newAlignedPinned #-}
435+newAlignedPinned :: (MonadIO m, Unboxed a) => Int -> Int -> m (Array a)
436+newAlignedPinned =
437+ newArrayWith (\s a -> liftIO $ Unboxed.newAlignedPinnedBytes s a)
438+
439+-- XXX can unaligned allocation be more efficient when alignment is not needed?
440+--
441+-- | Allocates an empty pinned array that can hold 'count' items. The memory of
442+-- the array is uninitialized and the allocation is aligned as per the 'Unboxed'
443+-- instance of the type.
444+--
445+-- /Pre-release/
446+{-# INLINE newPinned #-}
447+newPinned :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
448+newPinned = newAlignedPinned (alignment (undefined :: a))
449+
450+-- | Allocates an empty unpinned array that can hold 'count' items. The memory
451+-- of the array is uninitialized.
452+--
453+-- /Pre-release/
454+{-# INLINE new #-}
455+new :: (MonadIO m, Unboxed a) => Int -> m (Array a)
456+new =
457+ newArrayWith
458+ (\s _ -> liftIO $ Unboxed.newUnpinnedBytes s)
459+ (error "new: alignment is not used in unpinned arrays.")
460+
464461-- | Allocate an Array of the given size and run an IO action passing the array
465462-- start pointer.
466463--
@@ -469,7 +466,7 @@ newPinnedArrayBytes bytes = do
469466withNewArrayUnsafe ::
470467 (MonadIO m, Unboxed a) => Int -> (Ptr a -> m ()) -> m (Array a)
471468withNewArrayUnsafe count f = do
472− arr <- newArray count
469+ arr <- newPinned count
473470 asPtrUnsafe arr
474471 $ \p -> f p >> return arr
475472
@@ -719,7 +716,7 @@ reallocAligned elemSize alignSize newCapacityInBytes Array{..} = do
719716
720717 -- Allocate new array
721718 let newCapMaxInBytes = roundUpLargeArray newCapacityInBytes
722− contents <- newAlignedArrayContents newCapMaxInBytes alignSize
719+ contents <- Unboxed.newAlignedPinnedBytes newCapMaxInBytes alignSize
723720 let !(MutableByteArray mbarrFrom#) = arrContents
724721 !(MutableByteArray mbarrTo#) = contents
725722
@@ -1310,7 +1307,7 @@ arraysOf n (D.Stream step state) =
13101307 error $ "Streamly.Internal.Data.Array.Unboxed.Mut.Type.arraysOf: "
13111308 ++ "the size of arrays [" ++ show n
13121309 ++ "] must be a natural number"
1313− Array contents start end bound <- liftIO $ newArray n
1310+ Array contents start end bound <- liftIO $ newPinned n
13141311 return $ D.Skip (GroupBuffer st contents start end bound)
13151312
13161313 step' gst (GroupBuffer st contents start end bound) = do
@@ -1749,13 +1746,13 @@ writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
17491746-- conditional in the step function blocks fusion causing 10x performance
17501747-- slowdown.
17511748--
1752−-- >>> writeNUnsafe = Array.writeNWithUnsafe Array.newArray
1749+-- >>> writeNUnsafe = Array.writeNWithUnsafe Array.newPinned
17531750--
17541751-- @since 0.7.0
17551752{-# INLINE_NORMAL writeNUnsafe #-}
17561753writeNUnsafe :: forall m a. (MonadIO m, Unboxed a)
17571754 => Int -> Fold m a (Array a)
1758−writeNUnsafe = writeNWithUnsafe newArray
1755+writeNUnsafe = writeNWithUnsafe newPinned
17591756
17601757-- | @writeNWith alloc n@ folds a maximum of @n@ elements into an array
17611758-- allocated using the @alloc@ function.
@@ -1771,14 +1768,14 @@ writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
17711768-- | @writeN n@ folds a maximum of @n@ elements from the input stream to an
17721769-- 'Array'.
17731770--
1774−-- >>> writeN = Array.writeNWith Array.newArray
1771+-- >>> writeN = Array.writeNWith Array.newPinned
17751772-- >>> writeN n = Fold.take n (Array.writeNUnsafe n)
1776−-- >>> writeN n = Array.appendN (Array.newArray n) n
1773+-- >>> writeN n = Array.appendN (Array.newPinned n) n
17771774--
17781775-- @since 0.7.0
17791776{-# INLINE_NORMAL writeN #-}
17801777writeN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
1781−writeN = writeNWith newArray
1778+writeN = writeNWith newPinned
17821779
17831780-- | Like writeNWithUnsafe but writes the array in reverse order.
17841781--
@@ -1814,20 +1811,20 @@ writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
18141811-- /Pre-release/
18151812{-# INLINE_NORMAL writeRevN #-}
18161813writeRevN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
1817−writeRevN = writeRevNWith newArray
1814+writeRevN = writeRevNWith newPinned
18181815
18191816-- | @writeNAligned align n@ folds a maximum of @n@ elements from the input
18201817-- stream to an 'Array' aligned to the given size.
18211818--
1822−-- >>> writeNAligned align = Array.writeNWith (Array.newArrayAligned align)
1823−-- >>> writeNAligned align n = Array.appendN (Array.newArrayAligned align n) n
1819+-- >>> writeNAligned align = Array.writeNWith (Array.newAlignedPinned align)
1820+-- >>> writeNAligned align n = Array.appendN (Array.newAlignedPinned align n) n
18241821--
18251822-- /Pre-release/
18261823--
18271824{-# INLINE_NORMAL writeNAligned #-}
18281825writeNAligned :: forall m a. (MonadIO m, Unboxed a)
18291826 => Int -> Int -> Fold m a (Array a)
1830−writeNAligned align = writeNWith (newArrayAligned align)
1827+writeNAligned align = writeNWith (newAlignedPinned align)
18311828
18321829-- XXX Buffer to a list instead?
18331830--
@@ -1870,7 +1867,7 @@ writeChunks n = FL.many (writeN n) FL.toStreamK
18701867--
18711868-- /Caution! Do not use this on infinite streams./
18721869--
1873−-- >>> f n = Array.appendWith (* 2) (Array.newArray n)
1870+-- >>> f n = Array.appendWith (* 2) (Array.newPinned n)
18741871-- >>> writeWith n = Fold.rmapM Array.rightSize (f n)
18751872-- >>> writeWith n = Fold.rmapM Array.fromArrayStreamK (Array.writeChunks n)
18761873--
@@ -1878,7 +1875,7 @@ writeChunks n = FL.many (writeN n) FL.toStreamK
18781875{-# INLINE_NORMAL writeWith #-}
18791876writeWith :: forall m a. (MonadIO m, Unboxed a)
18801877 => Int -> Fold m a (Array a)
1881−-- writeWith n = FL.rmapM rightSize $ appendWith (* 2) (newArray n)
1878+-- writeWith n = FL.rmapM rightSize $ appendWith (* 2) (newPinned n)
18821879writeWith elemCount =
18831880 FL.rmapM extract $ FL.foldlM' step initial
18841881
@@ -1890,7 +1887,7 @@ writeWith elemCount =
18901887
18911888 initial = do
18921889 when (elemCount < 0) $ error "writeWith: elemCount is negative"
1893− liftIO $ newArrayAligned (alignment (undefined :: a)) elemCount
1890+ liftIO $ newAlignedPinned (alignment (undefined :: a)) elemCount
18941891 step arr@(Array _ start end bound) x
18951892 | INDEX_NEXT(end,a) > bound = do
18961893 let oldSize = end - start
@@ -1931,7 +1928,7 @@ fromStreamDN :: forall m a. (MonadIO m, Unboxed a)
19311928 => Int -> D.Stream m a -> m (Array a)
19321929-- fromStreamDN n = D.fold (writeN n)
19331930fromStreamDN limit str = do
1934− arr <- liftIO $ newArray limit
1931+ arr <- liftIO $ newPinned limit
19351932 end <- D.foldlM' (fwrite (arrContents arr)) (return $ arrEnd arr) $ D.take limit str
19361933 return $ arr {arrEnd = end}
19371934
@@ -2038,7 +2035,7 @@ spliceCopy arr1 arr2 = liftIO $ do
20382035 len2 = arrEnd arr2 - start2
20392036 newArrContents <-
20402037 liftIO
2041− $ newAlignedArrayContents
2038+ $ Unboxed.newAlignedPinnedBytes
20422039 (len1 + len2)
20432040 (alignment (undefined :: a))
20442041 let len = len1 + len2
core/src/Streamly/Internal/Data/Array/Unboxed/Stream.hs+3−3
@@ -473,7 +473,7 @@ foldlM' step begin = D.foldlM' step begin . S.toStreamD
473473spliceArraysLenUnsafe :: (MonadIO m, Unboxed a)
474474 => Int -> Stream m (MA.Array a) -> m (MA.Array a)
475475spliceArraysLenUnsafe len buffered = do
476− arr <- liftIO $ MA.newArray len
476+ arr <- liftIO $ MA.newPinned len
477477 foldlM' MA.spliceUnsafe (return arr) buffered
478478
479479{-# INLINE _spliceArrays #-}
@@ -482,7 +482,7 @@ _spliceArrays :: (MonadIO m, Unboxed a)
482482_spliceArrays s = do
483483 buffered <- S.foldr S.cons S.nil s
484484 len <- S.fold FL.sum (fmap Array.length buffered)
485− arr <- liftIO $ MA.newArray len
485+ arr <- liftIO $ MA.newPinned len
486486 final <- foldlM' writeArr (return arr) s
487487 return $ A.unsafeFreeze final
488488
@@ -503,7 +503,7 @@ spliceArraysRealloced :: forall m a. (MonadIO m, Unboxed a)
503503 => Stream m (Array a) -> m (Array a)
504504spliceArraysRealloced s = do
505505 let n = allocBytesToElemCount (undefined :: a) (4 * 1024)
506− idst = liftIO $ MA.newArray n
506+ idst = liftIO $ MA.newPinned n
507507
508508 arr <- foldlM' MA.spliceExp idst (fmap A.unsafeThaw s)
509509 liftIO $ A.unsafeFreeze <$> MA.rightSize arr
core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+3−2
@@ -94,12 +94,13 @@ import Text.Read (readPrec, readListPrec, readListPrecDefault)
9494
9595import Prelude hiding (length, foldr, read, unlines, splitAt)
9696
97+import qualified GHC.Exts as Exts
9798import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
9899import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
99100import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
100101import qualified Streamly.Internal.Data.Stream.Type as Stream
102+import qualified Streamly.Internal.Data.Unboxed as Unboxed
101103import qualified Streamly.Internal.Data.Unfold.Type as Unfold
102−import qualified GHC.Exts as Exts
103104
104105import Streamly.Internal.System.IO (unsafeInlineIO, defaultChunkSize)
105106
@@ -595,7 +596,7 @@ nil ::
595596 Unboxed a =>
596597#endif
597598 Array a
598−nil = Array MA.nilArrayContents 0 0
599+nil = Array Unboxed.nil 0 0
599600
600601instance Unboxed a => Monoid (Array a) where
601602 mempty = nil
core/src/Streamly/Internal/Data/Fold.hs+1−1
@@ -2812,7 +2812,7 @@ topBy cmp n = Fold step initial extract
28122812 where
28132813
28142814 initial = do
2815− arr <- MA.newArray n
2815+ arr <- MA.newPinned n
28162816 if n <= 0
28172817 then return $ Done arr
28182818 else return $ Partial (arr, 0)
core/src/Streamly/Internal/Data/IORef/Unboxed.hs+2−2
@@ -45,7 +45,7 @@ import Streamly.Internal.Data.Unboxed
4545 , sizeOf
4646 , peekWith
4747 , pokeWith
48− , newUnpinnedArrayContents
48+ , newUnpinnedBytes
4949 )
5050
5151import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
@@ -59,7 +59,7 @@ newtype IORef a = IORef (MutableByteArray a)
5959{-# INLINE newIORef #-}
6060newIORef :: forall a. Unboxed a => a -> IO (IORef a)
6161newIORef x = do
62− var <- newUnpinnedArrayContents (sizeOf (undefined :: a))
62+ var <- newUnpinnedBytes (sizeOf (undefined :: a))
6363 pokeWith var 0 x
6464 return $ IORef var
6565
core/src/Streamly/Internal/Data/Ring/Unboxed.hs+1−1
@@ -579,7 +579,7 @@ slidingWindowWith n (Fold step1 initial1 extract1) = Fold step initial extract
579579 Done b -> Done b
580580
581581 toArray foldRing rb rh = do
582− arr <- liftIO $ MA.newArray n
582+ arr <- liftIO $ MA.newPinned n
583583 let snoc' b a = liftIO $ MA.snocUnsafe b a
584584 foldRing rh snoc' arr rb
585585
core/src/Streamly/Internal/Data/Unboxed.hs+23−6
@@ -14,7 +14,9 @@ module Streamly.Internal.Data.Unboxed
1414 , getMutableByteArray#
1515 , pin
1616 , unpin
17− , newUnpinnedArrayContents
17+ , newUnpinnedBytes
18+ , newAlignedPinnedBytes
19+ , nil
1820 ) where
1921
2022#include "MachDeps.h"
@@ -36,6 +38,7 @@ import GHC.Word (Word16(..), Word32(..), Word64(..), Word8(..))
3638#if MIN_VERSION_base(4,15,0)
3739import GHC.RTS.Flags (IoSubSystem(..))
3840#endif
41+import System.IO.Unsafe (unsafePerformIO)
3942
4043import GHC.Exts
4144
@@ -63,16 +66,30 @@ touch (MutableByteArray contents) =
6366-- Creation
6467--------------------------------------------------------------------------------
6568
66−{-# INLINE newUnpinnedArrayContents #-}
67−newUnpinnedArrayContents :: Int -> IO (MutableByteArray a)
68−newUnpinnedArrayContents nbytes | nbytes < 0 =
69− errorWithoutStackTrace "newUnpinnedArrayContents: size must be >= 0"
70−newUnpinnedArrayContents (I# nbytes) = IO $ \s ->
69+{-# NOINLINE nil #-}
70+nil :: MutableByteArray a
71+nil = unsafePerformIO $ newUnpinnedBytes 0
72+
73+{-# INLINE newUnpinnedBytes #-}
74+newUnpinnedBytes :: Int -> IO (MutableByteArray a)
75+newUnpinnedBytes nbytes | nbytes < 0 =
76+ errorWithoutStackTrace "newUnpinnedBytes: size must be >= 0"
77+newUnpinnedBytes (I# nbytes) = IO $ \s ->
7178 case newByteArray# nbytes s of
7279 (# s', mbarr# #) ->
7380 let c = MutableByteArray mbarr#
7481 in (# s', c #)
7582
83+{-# INLINE newAlignedPinnedBytes #-}
84+newAlignedPinnedBytes :: Int -> Int -> IO (MutableByteArray a)
85+newAlignedPinnedBytes nbytes _align | nbytes < 0 =
86+ errorWithoutStackTrace "newAlignedPinnedBytes: size must be >= 0"
87+newAlignedPinnedBytes (I# nbytes) (I# align) = IO $ \s ->
88+ case newAlignedPinnedByteArray# nbytes align s of
89+ (# s', mbarr# #) ->
90+ let c = MutableByteArray mbarr#
91+ in (# s', c #)
92+
7693-------------------------------------------------------------------------------
7794-- Pinning & Unpinning
7895-------------------------------------------------------------------------------
core/src/Streamly/Internal/FileSystem/Handle.hs+1−1
@@ -180,7 +180,7 @@ import qualified Streamly.Internal.Data.Stream.StreamK.Type as K (mkStream)
180180{-# INLINABLE getChunk #-}
181181getChunk :: MonadIO m => Int -> Handle -> m (Array Word8)
182182getChunk size h = liftIO $ do
183− arr <- MArray.newPinnedArrayBytes size
183+ arr <- MArray.newPinnedBytes size
184184 -- ptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: Word8))
185185 MArray.asPtrUnsafe arr $ \p -> do
186186 n <- hGetBufSome h p size
src/Streamly/Internal/FileSystem/FD.hs+2−2
@@ -146,7 +146,7 @@ import qualified Streamly.Internal.System.IOVec.Type as RawIO
146146import qualified Streamly.Data.Array.Unboxed as A
147147import qualified Streamly.Data.Fold as FL
148148import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
149− (Array(..), newPinnedArrayBytes, asPtrUnsafe)
149+ (Array(..), newPinnedBytes, asPtrUnsafe)
150150import qualified Streamly.Internal.Data.Array.Unboxed.Stream as AS
151151import qualified Streamly.Internal.Data.Stream as S
152152import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
@@ -217,7 +217,7 @@ openFile path mode = Handle . fst <$> FD.openFile path mode True
217217{-# INLINABLE readArrayUpto #-}
218218readArrayUpto :: Int -> Handle -> IO (Array Word8)
219219readArrayUpto size (Handle fd) = do
220− arr <- MArray.newPinnedArrayBytes size
220+ arr <- MArray.newPinnedBytes size
221221 -- ptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: Word8))
222222 MArray.asPtrUnsafe arr $ \p -> do
223223 -- n <- hGetBufSome h p size
src/Streamly/Internal/Network/Socket.hs+2−2
@@ -104,7 +104,7 @@ import qualified Streamly.Data.Fold as FL
104104import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
105105 (unsafeFreeze, asPtrUnsafe, byteLength, writeNUnsafe)
106106import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
107− (Array(..), newPinnedArrayBytes, asPtrUnsafe)
107+ (Array(..), newPinnedBytes, asPtrUnsafe)
108108import qualified Streamly.Internal.Data.Array.Unboxed.Stream as AS
109109import qualified Streamly.Internal.Data.Stream as S
110110import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
@@ -261,7 +261,7 @@ readArrayUptoWith
261261 -> h
262262 -> IO (Array Word8)
263263readArrayUptoWith f size h = do
264− arr <- MArray.newPinnedArrayBytes size
264+ arr <- MArray.newPinnedBytes size
265265 -- ptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: Word8))
266266 MArray.asPtrUnsafe arr $ \p -> do
267267 n <- f h p size
test/Streamly/Test/Data/Array/Unboxed.hs+2−2
@@ -155,7 +155,7 @@ testBubbleWith asc =
155155 else MA.bubble (flip compare) arr
156156 return arr
157157 )
158− (MA.newArray $ length ls)
158+ (MA.newPinned $ length ls)
159159
160160testBubbleAsc :: Property
161161testBubbleAsc = testBubbleWith True
@@ -165,7 +165,7 @@ testBubbleDesc = testBubbleWith False
165165
166166testByteLengthWithMA :: forall a. Unboxed a => a -> IO ()
167167testByteLengthWithMA _ = do
168− arrA <- MA.newArray 100 :: IO (MA.Array a)
168+ arrA <- MA.newPinned 100 :: IO (MA.Array a)
169169 let arrW8 = MA.castUnsafe arrA :: MA.Array Word8
170170 MA.byteLength arrA `shouldBe` MA.length arrW8
171171
test/Streamly/Test/Data/Array/Unboxed/Mut.hs+1−1
@@ -42,7 +42,7 @@ testAppend =
4242
4343 action ls = do
4444 x <- Stream.fold
45− (MArray.append (MArray.newArray 0))
45+ (MArray.append (MArray.newPinned 0))
4646 (Stream.fromList (ls::[Int]))
4747 lst <- MArray.toList x
4848 assert (ls == lst)