Copyright | (c) Alexey Kuleshevich 2020 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <alexey@kuleshevi.ch> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- newtype PArray (p :: Pinned) e = PArray (Bytes p)
- newtype PMArray (p :: Pinned) e s = PMArray (MBytes p s)
- data Pinned
- fromBytesPArray :: Bytes p -> PArray p e
- toBytesPArray :: PArray p e -> Bytes p
- fromUArrayPArray :: UArray e -> PArray 'Inc e
- toUArrayPArray :: PArray p e -> UArray e
- castPArray :: PArray p e' -> PArray p e
- fromMBytesPMArray :: MBytes p s -> PMArray p e s
- toMBytesPMArray :: PMArray p e s -> MBytes p s
- fromUMArrayPMArray :: UMArray e s -> PMArray 'Inc e s
- toUMArrayPMArray :: PMArray p e s -> UMArray e s
- castPMArray :: PMArray p e' s -> PMArray p e s
- allocPMArray :: forall e p m s. (Typeable p, Prim e, MonadPrim s m) => Size -> m (PMArray p e s)
- allocPinnedPMArray :: forall e m s. (MonadPrim s m, Prim e) => Size -> m (PMArray 'Pin e s)
- allocAlignedPMArray :: (MonadPrim s m, Prim e) => Count e -> m (PMArray 'Pin e s)
- allocUnpinnedPMArray :: forall e m s. (MonadPrim s m, Prim e) => Size -> m (PMArray 'Inc e s)
- shrinkPMArray :: forall e p m s. (MonadPrim s m, Prim e) => PMArray p e s -> Size -> m ()
- resizePMArray :: forall e p m s. (MonadPrim s m, Prim e) => PMArray p e s -> Size -> m (PMArray 'Inc e s)
- reallocPMArray :: forall e p m s. (MonadPrim s m, Typeable p, Prim e) => PMArray p e s -> Size -> m (PMArray p e s)
- isPinnedPArray :: PArray p e -> Bool
- isPinnedPMArray :: PMArray p e s -> Bool
- thawPArray :: MonadPrim s m => PArray p e -> m (PMArray p e s)
- freezePMArray :: MonadPrim s m => PMArray p e s -> m (PArray p e)
- sizePArray :: forall e p. Prim e => PArray p e -> Size
- getSizePMArray :: forall e p m s. (MonadPrim s m, Prim e) => PMArray p e s -> m Size
- readPMArray :: (MonadPrim s m, Prim e) => PMArray p e s -> Int -> m e
- writePMArray :: (MonadPrim s m, Prim e) => PMArray p e s -> Int -> e -> m ()
- setPMArray :: forall e p m s. (MonadPrim s m, Prim e) => PMArray p e s -> Int -> Size -> e -> m ()
- copyPArrayToPMArray :: forall e p m s. (MonadPrim s m, Prim e) => PArray p e -> Int -> PMArray p e s -> Int -> Size -> m ()
- movePMArrayToPMArray :: forall e p m s. (MonadPrim s m, Prim e) => PMArray p e s -> Int -> PMArray p e s -> Int -> Size -> m ()
Documentation
newtype PArray (p :: Pinned) e Source #
An immutable array with elements of type e
Instances
newtype PMArray (p :: Pinned) e s Source #
A mutable array with elements of type e
Instances
In GHC there is a distinction between pinned and unpinned memory.
Pinned memory is such that when allocated, it is guaranteed not to move throughout the
lifetime of a program. In other words the address pointer that refers to allocated
bytes will not change until the associated ByteArray#
or MutableByteArray#
is no
longer referenced anywhere in the program at which point it gets garbage collected. On
the other hand unpinned memory can be moved around during GC, which helps to reduce
memory fragmentation.
Pinned/unpinnned choice during allocation is a bit of a lie, because when attempt is
made to allocate memory as unpinned, but requested size is a bit more than a certain
threshold (somewhere around 3KiB) it might still be allocated as pinned. Because of
that fact through out the "primal" universe there is a distinction between memory that
is either
or Pin
ned
.Inc
onclusive
It is possible to use one of toPinnedBytes
or
toPinnedMBytes
to get a conclusive type.
Since: 0.1.0
fromBytesPArray :: Bytes p -> PArray p e Source #
toBytesPArray :: PArray p e -> Bytes p Source #
castPArray :: PArray p e' -> PArray p e Source #
fromMBytesPMArray :: MBytes p s -> PMArray p e s Source #
toMBytesPMArray :: PMArray p e s -> MBytes p s Source #
castPMArray :: PMArray p e' s -> PMArray p e s Source #
allocPMArray :: forall e p m s. (Typeable p, Prim e, MonadPrim s m) => Size -> m (PMArray p e s) Source #
allocPinnedPMArray :: forall e m s. (MonadPrim s m, Prim e) => Size -> m (PMArray 'Pin e s) Source #
allocUnpinnedPMArray :: forall e m s. (MonadPrim s m, Prim e) => Size -> m (PMArray 'Inc e s) Source #
shrinkPMArray :: forall e p m s. (MonadPrim s m, Prim e) => PMArray p e s -> Size -> m () Source #
Shrink mutable bytes to new specified count of elements. The new count must be less
than or equal to the current count as reported by getCountPMArray
.
resizePMArray :: forall e p m s. (MonadPrim s m, Prim e) => PMArray p e s -> Size -> m (PMArray 'Inc e s) Source #
Attempt to resize mutable bytes in place.
- New bytes might be allocated, with the copy of an old one.
- Old references should not be kept around to allow GC to claim it
- Old references should not be used to avoid undefined behavior
reallocPMArray :: forall e p m s. (MonadPrim s m, Typeable p, Prim e) => PMArray p e s -> Size -> m (PMArray p e s) Source #
isPinnedPArray :: PArray p e -> Bool Source #
isPinnedPMArray :: PMArray p e s -> Bool Source #