primal-memory-0.3.0.0: Unified interface for memory managemenet.
Copyright (c) Alexey Kuleshevich 2020 BSD3 Alexey Kuleshevich experimental non-portable None Haskell2010

Description

Synopsis

Constructors

#### Instances

Instances details

curOffAddr :: Prim e => Addr e -> Off e Source #

countAddr :: forall e. Prim e => Addr e -> Count e Source #

indexOffAddr :: Prim e => Addr e -> Off e -> e Source #

withPtrAddr :: MonadPrim s m => Addr e -> (Ptr e -> m b) -> m b Source #

withNoHaltPtrAddr :: MonadUnliftPrim s m => Addr e -> (Ptr e -> m b) -> m b Source #

data MAddr e s Source #

Constructors

#### Instances

Instances details

newMAddr :: forall e m s. (MonadPrim s m, Prim e) => e -> m (MAddr e s) Source #

allocMAddr :: forall e m s. (MonadPrim s m, Prim e) => Count e -> m (MAddr e s) Source #

allocAlignedMAddr :: forall e m s. (MonadPrim s m, Prim e) => Count e -> m (MAddr e s) Source #

allocZeroMAddr :: forall e m s. (MonadPrim s m, Prim e) => Count e -> m (MAddr e s) Source #

allocZeroAlignedMAddr :: forall e m s. (MonadPrim s m, Prim e) => Count e -> m (MAddr e s) Source #

shrinkMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Count e -> m () Source #

Shrink mutable address to new specified size in number of elements. The new count must be less than or equal to the current as reported by getCountMAddr.

shrinkByteCountMAddr :: MonadPrim s m => MAddr e s -> Count Word8 -> m () Source #

Shrink mutable address to new specified size in bytes. The new count must be less than or equal to the current as reported by getByteCountMAddr.

setMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> Count e -> e -> m () Source #

curOffMAddr :: forall e s. Prim e => MAddr e s -> Off e Source #

getCountMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> m (Count e) Source #

plusOffMAddr :: Prim e => MAddr e s -> Off e -> MAddr e s Source #

writeMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> e -> m () Source #

writeOffMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> e -> m () Source #

writeByteOffMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off Word8 -> e -> m () Source #

copyAddrToMAddr :: (MonadPrim s m, Prim e) => Addr e -> Off e -> MAddr e s -> Off e -> Count e -> m () Source #

moveMAddrToMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> MAddr e s -> Off e -> Count e -> m () Source #

modifyMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> (a, b)) -> m b Source #

Apply a pure function to the contents of a mutable variable. Returns the artifact of computation.

Since: 0.2.0

modifyMAddr_ :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m () Source #

Apply a pure function to the contents of a mutable variable.

Since: 0.1.0

modifyFetchOldMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m a Source #

Apply a pure function to the contents of a mutable variable. Returns the old value.

Since: 2.0.0

modifyFetchNewMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m a Source #

Apply a pure function to the contents of a mutable variable. Returns the new value.

Since: 2.0.0

modifyMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m (a, b)) -> m b Source #

Apply a monadic action to the contents of a mutable variable. Returns the artifact of computation.

Since: 0.2.0

modifyMAddrM_ :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m () Source #

Apply a monadic action to the contents of a mutable variable.

Since: 0.1.0

modifyFetchOldMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m a Source #

Apply a monadic action to the contents of a mutable variable. Returns the old value.

Since: 2.0.0

modifyFetchNewMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m a Source #

Apply a monadic action to the contents of a mutable variable. Returns the new value.

Since: 2.0.0

Swap contents of two mutable variables.

Since: 0.1.0

Swap contents of two mutable variables. Returns their old values.

Since: 0.1.0

withPtrMAddr :: MonadPrim s m => MAddr e s -> (Ptr e -> m b) -> m b Source #

withNoHaltPtrMAddr :: MonadUnliftPrim s m => MAddr e s -> (Ptr e -> m b) -> m b Source #

This is a unsafe cast therefore modification of ForeignPtr will be reflected in resulting immutable Addr. Pointer created with malloc cannot be converted to Addr and will result in Nothing

Since: 0.1.0

Discarding the original ForeignPtr will trigger finalizers that were attached to it, because MAddr does not retain any finalizers. Pointer created with malloc cannot be converted to MAddr and will result in Nothing

Since: 0.1.0

# Conversion

## ByteString

O(1) - Cast an immutable Addr to an immutable ByteString

Since: 0.1.0

O(1) - Cast an immutable Addr to an immutable ShortByteString

Since: 0.1.0

O(n) - Convert an immutable ShortByteString to an immutable Addr. In a most common case when ShortByteString is not backed by pinned memory, this function will return Nothing.

Since: 0.1.0

O(1) - Cast an immutable ByteString to Addr. Also returns the original length of ByteString, which will be less or equal to countOfAddr in the produced Addr.

Since: 0.1.0

O(1) - Cast an immutable ByteString to a mutable MAddr. Also returns the original length of ByteString, which will be less or equal to getCountOfMAddr in the produced MAddr.

Unsafe - Further modification of MAddr will affect the source ByteString

Since: 0.1.0

# Atomic

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes. -> e Expected old value -> e New value -> m e

Perform atomic modification of an element in the MAddr at the supplied index. Returns the artifact of computation b. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes. -> e Expected old value -> e New value -> m Bool

Perform atomic modification of an element in the MAddr at the supplied index. Returns True if swap was successfull and false otherwise. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes. -> e Expected old value -> e New value -> m (Bool, e)

Just like casBoolOffMAddr, but also returns the actual value, which will match the supplied expected value if the returned flag is True

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes. -> m e

Perform atomic read of an element in the MAddr at the supplied offset. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes. -> e -> m ()

Perform atomic write of an element in the MAddr at the supplied offset. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes. -> (e -> (e, b)) Function that is applied to the old value and returns new value and some artifact of computation b -> m b

Perform atomic modification of an element in the MAddr at the supplied index. Returns the artifact of computation b. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes. -> (e -> e) Function that is applied to the current value -> m ()

Perform atomic modification of an element in the MAddr at the supplied index. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes. -> (e -> e) Function that is applied to the old value -> m e Returns the old value

Perform atomic modification of an element in the MAddr at the supplied index. Returns the previous value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Arguments

 :: (MonadPrim s m, Atomic e) => MAddr e s Array to be mutated -> Off e Index is in elements of e, rather than bytes -> (e -> e) Function that is applied to the old value -> m e Returns the new value

Perform atomic modification of an element in the MAddr at the supplied index. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

## Numeric

Add a numeric value to an element of a MAddr, corresponds to (+) done atomically. Returns the previous value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

Add a numeric value to an element of a MAddr, corresponds to (+) done atomically. Returns the new value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicSubFetchOldOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e Source #

Subtract a numeric value from an element of a MAddr, corresponds to (-) done atomically. Returns the previous value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicSubFetchNewOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e Source #

Subtract a numeric value from an element of a MAddr, corresponds to (-) done atomically. Returns the new value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

## Binary

atomicAndFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #

Binary conjunction (AND) of an element of a MAddr with the supplied value, corresponds to (.&.) done atomically. Returns the previous value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicAndFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #

Binary conjunction (AND) of an element of a MAddr with the supplied value, corresponds to (.&.) done atomically. Returns the new value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicNandFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #

Negation of binary conjunction (NAND) of an element of a MAddr with the supplied value, corresponds to \x y -> complement (x .&. y) done atomically. Returns the previous value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicNandFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #

Negation of binary conjunction (NAND) of an element of a MAddr with the supplied value, corresponds to \x y -> complement (x .&. y) done atomically. Returns the new value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicOrFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #

Binary disjunction (OR) of an element of a MAddr with the supplied value, corresponds to (.|.) done atomically. Returns the previous value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicOrFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #

Binary disjunction (OR) of an element of a MAddr with the supplied value, corresponds to (.|.) done atomically. Returns the new value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicXorFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #

Binary exclusive disjunction (XOR) of an element of a MAddr with the supplied value, corresponds to xor done atomically. Returns the previous value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicXorFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #

Binary exclusive disjunction (XOR) of an element of a MAddr with the supplied value, corresponds to xor done atomically. Returns the new value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicNotFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> m e Source #

Binary negation (NOT) of an element of a MAddr, corresponds to (complement) done atomically. Returns the previous value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

atomicNotFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> m e Source #

Binary negation (NOT) of an element of a MAddr, corresponds to (complement) done atomically. Returns the new value. Offset is in number of elements, rather than bytes. Implies a full memory barrier.

Note - Bounds are not checked, therefore this function is unsafe.

Since: 0.1.0

# Prefetch

## With offset

prefetchOffAddr0 :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m () Source #

prefetchOffMAddr0 :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m () Source #

prefetchOffAddr1 :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m () Source #

prefetchOffMAddr1 :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m () Source #

prefetchOffAddr2 :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m () Source #

prefetchOffMAddr2 :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m () Source #

prefetchOffAddr3 :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m () Source #

prefetchOffMAddr3 :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m () Source #

module Data.Prim