primal-memory-0.2.0.0: Unified interface for memory managemenet.

Copyright(c) Alexey Kuleshevich 2020
LicenseBSD3
MaintainerAlexey Kuleshevich <alexey@kuleshevi.ch>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Prim.Memory.PrimArray

Description

 
Synopsis

Documentation

newtype PrimArray (p :: Pinned) e Source #

An immutable array of bytes of type e

Constructors

PrimArray (Bytes p) 
Instances
PtrAccess s (PrimArray Pin e) Source #

Read-only access, but it is not enforced.

Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

toForeignPtr :: MonadPrim s m => PrimArray Pin e -> m (ForeignPtr a) Source #

withPtrAccess :: MonadPrim s m => PrimArray Pin e -> (Ptr a -> m b) -> m b Source #

withNoHaltPtrAccess :: MonadUnliftPrim s m => PrimArray Pin e -> (Ptr a -> m b) -> m b Source #

(Typeable p, Prim e) => IsList (PrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Associated Types

type Item (PrimArray p e) :: Type #

Methods

fromList :: [Item (PrimArray p e)] -> PrimArray p e #

fromListN :: Int -> [Item (PrimArray p e)] -> PrimArray p e #

toList :: PrimArray p e -> [Item (PrimArray p e)] #

(Show e, Prim e) => Show (PrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

showsPrec :: Int -> PrimArray p e -> ShowS #

show :: PrimArray p e -> String #

showList :: [PrimArray p e] -> ShowS #

Typeable p => IsString (PrimArray p Char) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Typeable p => Semigroup (PrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

(<>) :: PrimArray p e -> PrimArray p e -> PrimArray p e #

sconcat :: NonEmpty (PrimArray p e) -> PrimArray p e #

stimes :: Integral b => b -> PrimArray p e -> PrimArray p e #

Typeable p => Monoid (PrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

mempty :: PrimArray p e #

mappend :: PrimArray p e -> PrimArray p e -> PrimArray p e #

mconcat :: [PrimArray p e] -> PrimArray p e #

NFData (PrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

rnf :: PrimArray p e -> () #

MemRead (PrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

byteCountMem :: PrimArray p e -> Count Word8 Source #

indexOffMem :: Prim e0 => PrimArray p e -> Off e0 -> e0 Source #

indexByteOffMem :: Prim e0 => PrimArray p e -> Off Word8 -> e0 Source #

copyByteOffToMBytesMem :: (MonadPrim s m, Prim e0) => PrimArray p e -> Off Word8 -> MBytes p0 s -> Off Word8 -> Count e0 -> m () Source #

copyByteOffToPtrMem :: (MonadPrim s m, Prim e0) => PrimArray p e -> Off Word8 -> Ptr e0 -> Off Word8 -> Count e0 -> m () Source #

compareByteOffToPtrMem :: (MonadPrim s m, Prim e0) => PrimArray p e -> Off Word8 -> Ptr e0 -> Off Word8 -> Count e0 -> m Ordering Source #

compareByteOffToBytesMem :: Prim e0 => PrimArray p e -> Off Word8 -> Bytes p0 -> Off Word8 -> Count e0 -> Ordering Source #

compareByteOffMem :: (MemRead mr', Prim e0) => mr' -> Off Word8 -> PrimArray p e -> Off Word8 -> Count e0 -> Ordering Source #

type Item (PrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

type Item (PrimArray p e) = e

newtype MPrimArray (p :: Pinned) e s Source #

A mutable array of bytes of type e

Constructors

MPrimArray (MBytes p s) 
Instances
PtrAccess s (MPrimArray Pin e s) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

toForeignPtr :: MonadPrim s m => MPrimArray Pin e s -> m (ForeignPtr a) Source #

withPtrAccess :: MonadPrim s m => MPrimArray Pin e s -> (Ptr a -> m b) -> m b Source #

withNoHaltPtrAccess :: MonadUnliftPrim s m => MPrimArray Pin e s -> (Ptr a -> m b) -> m b Source #

Typeable p => MemAlloc (MPrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Associated Types

type FrozenMem (MPrimArray p e) = (fm :: Type) Source #

Methods

getByteCountMem :: MonadPrim s m => MPrimArray p e s -> m (Count Word8) Source #

allocMem :: (Prim e0, MonadPrim s m) => Count e0 -> m (MPrimArray p e s) Source #

thawMem :: MonadPrim s m => FrozenMem (MPrimArray p e) -> m (MPrimArray p e s) Source #

freezeMem :: MonadPrim s m => MPrimArray p e s -> m (FrozenMem (MPrimArray p e)) Source #

resizeMem :: (MonadPrim s m, Prim e0) => MPrimArray p e s -> Count e0 -> m (MPrimArray p e s) Source #

MemWrite (MPrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

readOffMem :: (MonadPrim s m, Prim e0) => MPrimArray p e s -> Off e0 -> m e0 Source #

readByteOffMem :: (MonadPrim s m, Prim e0) => MPrimArray p e s -> Off Word8 -> m e0 Source #

writeOffMem :: (MonadPrim s m, Prim e0) => MPrimArray p e s -> Off e0 -> e0 -> m () Source #

writeByteOffMem :: (MonadPrim s m, Prim e0) => MPrimArray p e s -> Off Word8 -> e0 -> m () Source #

moveByteOffToMBytesMem :: (MonadPrim s m, Prim e0) => MPrimArray p e s -> Off Word8 -> MBytes p0 s -> Off Word8 -> Count e0 -> m () Source #

moveByteOffToPtrMem :: (MonadPrim s m, Prim e0) => MPrimArray p e s -> Off Word8 -> Ptr e0 -> Off Word8 -> Count e0 -> m () Source #

copyByteOffMem :: (MonadPrim s m, MemRead mr, Prim e0) => mr -> Off Word8 -> MPrimArray p e s -> Off Word8 -> Count e0 -> m () Source #

moveByteOffMem :: (MonadPrim s m, MemWrite mw', Prim e0) => mw' s -> Off Word8 -> MPrimArray p e s -> Off Word8 -> Count e0 -> m () Source #

setMem :: (MonadPrim s m, Prim e0) => MPrimArray p e s -> Off e0 -> Count e0 -> e0 -> m () Source #

NFData (MPrimArray p e s) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

Methods

rnf :: MPrimArray p e s -> () #

type FrozenMem (MPrimArray p e) Source # 
Instance details

Defined in Data.Prim.Memory.PrimArray

type FrozenMem (MPrimArray p e) = PrimArray p e

data Pinned Source #

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 Pinned or Inconclusive.

It is possible to use one of toPinnedBytes or toPinnedMBytes to get a conclusive type.

Since: 0.1.0

Constructors

Pin

Pinned, which indicates that allocated memory will not move

Inc

Inconclusive, thus memory could be pinned or unpinned

allocMPrimArray :: forall e p m s. (Typeable p, Prim e, MonadPrim s m) => Size -> m (MPrimArray p e s) Source #

allocPinnedMPrimArray :: forall e m s. (MonadPrim s m, Prim e) => Size -> m (MPrimArray Pin e s) Source #

allocAlignedMPrimArray Source #

Arguments

:: (MonadPrim s m, Prim e) 
=> Count e

Size in number of bytes

-> m (MPrimArray Pin e s) 

allocUnpinnedMPrimArray :: forall e m s. (MonadPrim s m, Prim e) => Size -> m (MPrimArray Inc e s) Source #

shrinkMPrimArray :: forall e p m s. (MonadPrim s m, Prim e) => MPrimArray 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 getCountMPrimArray.

resizeMPrimArray :: forall e p m s. (MonadPrim s m, Prim e) => MPrimArray p e s -> Size -> m (MPrimArray 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

reallocMPrimArray :: forall e p m s. (MonadPrim s m, Typeable p, Prim e) => MPrimArray p e s -> Size -> m (MPrimArray p e s) Source #

thawPrimArray :: MonadPrim s m => PrimArray p e -> m (MPrimArray p e s) Source #

sizePrimArray :: forall e p. Prim e => PrimArray p e -> Size Source #

getSizeMPrimArray :: forall e p m s. (MonadPrim s m, Prim e) => MPrimArray p e s -> m Size Source #

readMPrimArray :: (MonadPrim s m, Prim e) => MPrimArray p e s -> Int -> m e Source #

writeMPrimArray :: (MonadPrim s m, Prim e) => MPrimArray p e s -> Int -> e -> m () Source #

setMPrimArray Source #

Arguments

:: (MonadPrim s m, Prim e) 
=> MPrimArray p e s

Chunk of memory to fill

-> Int

Offset in number of elements

-> Size

Number of cells to fill

-> e

A value to fill the cells with

-> m () 

copyPrimArrayToMPrimArray :: forall e p m s. (MonadPrim s m, Prim e) => PrimArray p e -> Int -> MPrimArray p e s -> Int -> Size -> m () Source #

moveMPrimArrayToMPrimArray :: forall e p m s. (MonadPrim s m, Prim e) => MPrimArray p e s -> Int -> MPrimArray p e s -> Int -> Size -> m () Source #