Copyright | (c) 2019 Composewell Technologies |
---|---|
License | BSD3 |
Maintainer | streamly@composewell.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Deprecated: Use Streamly.Data.Array.Foreign instead
This module provides immutable arrays in pinned memory (non GC memory) suitable for long lived data storage, random access and for interfacing with the operating system.
Arrays in this module are chunks of pinned memory that hold a sequence of
Storable
values of a given type, they cannot store non-serializable data
like functions. Once created an array cannot be modified. Pinned memory
allows efficient buffering of long lived data without adding any impact to
GC. One array is just one pointer visible to GC and it does not have to be
copied across generations. Moreover, pinned memory allows communication
with foreign consumers and producers (e.g. file or network IO) without
copying the data.
Programmer Notes
To apply a transformation to an array use read
to unfold the array into a
stream, apply a transformation on the stream and then use write
to fold it
back to an array.
This module is designed to be imported qualified:
import qualified Streamly.Array as A
For experimental APIs see Streamly.Internal.Data.Array.Foreign.
Synopsis
- data Array a
- fromListN :: Storable a => Int -> [a] -> Array a
- fromList :: Storable a => [a] -> Array a
- writeN :: forall m a. (MonadIO m, Storable a) => Int -> Fold m a (Array a)
- write :: forall m a. (MonadIO m, Storable a) => Fold m a (Array a)
- toList :: Storable a => Array a -> [a]
- read :: forall m a. (Monad m, Storable a) => Unfold m (Array a) a
- length :: forall a. Storable a => Array a -> Int
Documentation
Instances
a ~ Char => IsString (Array a) Source # | |
Defined in Streamly.Internal.Data.Array.Foreign.Type fromString :: String -> Array a # | |
Storable a => Monoid (Array a) Source # | |
Storable a => Semigroup (Array a) Source # | |
Storable a => IsList (Array a) Source # | |
(Storable a, Read a, Show a) => Read (Array a) Source # | |
(Show a, Storable a) => Show (Array a) Source # | |
NFData (Array a) Source # | |
Defined in Streamly.Internal.Data.Array.Foreign.Type | |
(Storable a, Eq a) => Eq (Array a) Source # | |
(Storable a, Ord a) => Ord (Array a) Source # | |
Defined in Streamly.Internal.Data.Array.Foreign.Type | |
type Item (Array a) Source # | |
Defined in Streamly.Internal.Data.Array.Foreign.Type |
Arrays
Construction
When performance matters, the fastest way to generate an array is
writeN
. IsList
and IsString
instances can be
used to conveniently construct arrays from literal values.
OverloadedLists
extension or fromList
can be used to construct an
array from a list literal. Similarly, OverloadedStrings
extension or
fromList
can be used to construct an array from a string literal.
fromListN :: Storable a => Int -> [a] -> Array a Source #
Create an Array
from the first N elements of a list. The array is
allocated to size N, if the list terminates before N elements then the
array may hold less than N elements.
Since 0.7.0 (Streamly.Memory.Array)
Since: 0.8.0
fromList :: Storable a => [a] -> Array a Source #
Create an Array
from a list. The list must be of finite size.
Since 0.7.0 (Streamly.Memory.Array)
Since: 0.8.0
writeN :: forall m a. (MonadIO m, Storable a) => Int -> Fold m a (Array a) Source #
writeN n
folds a maximum of n
elements from the input stream to an
Array
.
Since 0.7.0 (Streamly.Memory.Array)
Since: 0.8.0
write :: forall m a. (MonadIO m, Storable a) => Fold m a (Array a) Source #
Fold the whole input to a single array.
Caution! Do not use this on infinite streams.
Since 0.7.0 (Streamly.Memory.Array)
Since: 0.8.0
Elimination
read :: forall m a. (Monad m, Storable a) => Unfold m (Array a) a Source #
Unfold an array into a stream.
Since 0.7.0 (Streamly.Memory.Array)
Since: 0.8.0