HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulepvar-1.0.0.0Haskell2010

Data.Primitive.PVar.Unsafe

  • 1 type
  • 25 values
  • Packagepvar-1.0.0.0
  • Exports26
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceInternal.hs
datadata PVar a s
#

Mutable variable with primitive value.

Constructors

Instances2Storable, NFData
  • Prim a => Storable (PVar a RealWorld)Defined in pvar-1.0.0.0 · Data.Primitive.PVar.Internal

    poke+peek will result in a new copy of a PVar

  • NFData (PVar a s)Defined in pvar-1.0.0.0 · Data.Primitive.PVar.Internal

    Values are already written into PVar in NF, this instance is trivial.

Creation

5 declarations
valuerawStorablePVar :: (MonadPrim s m, Storable a) => m (PVar a s)
#

Create a mutable variable in pinned uninitialized memory using Storable interface for getting the number of bytes for memory allocation.

valuerawAlignedStorablePVar :: (MonadPrim s m, Storable a) => m (PVar a s)
#

Create a mutable variable in pinned uninitialized memory using Storable interface for getting the number of bytes for memory allocation and alignement.

Access

2 declarations

Conversion

3 declarations
valuetoPtrPVar :: PVar a s -> Maybe (Ptr a)
#

Extract the address to the mutable variable, but only if it is backed by pinned memory. It is unsafe because even for pinned memory memory can be deallocated if associated PVar goes out of scope. Use withPtrPVar or Data.Primitive.PVar.toForeignPtr instead.

valueunsafeToPtrPVar :: PVar a s -> Ptr a
#

Get the address to the contents. This is highly unsafe, espcially if memory is not pinned

Reset

1 declaration

Unpacked opartions

3 declarations
valuesizeOfPVar# :: Prim a => PVar a s -> Int#
#

Get the size of the mutable variable in bytes as an unpacked integer

ByteArray

0 declarations

Atomic operations

Memory copying

valuecopyFromByteArrayPVar
  1. :: (MonadPrim s m, Prim a)
  2. => ByteArray

    Source array

  3. -> Int

    Offset in number of elements into the array

  4. -> PVar a s
  5. -> m ()
#

Copy the value from a frozen ByteArray into a mutable variable at specified index. Index of array is not checked and can result in an unchecked exception when incorrect

valuecopyPVarToMutableByteArray
  1. :: (MonadPrim s m, Prim a)
  2. => PVar a s
  3. -> MutableByteArray s
  4. -> Int

    Offset in number of elements into the array

  5. -> m ()
#

Copy the value from a mutable variable into a mutable array at the specified index. Index of array is not checked and can result in an unchecked exception when incorrect

Check if memory is pinned

Check whether or not the ByteArray is pinned.

Note - This function uses GHC built-in functions for GHC 8.2 and newer, but for older versions it fallsback onto custom implementation.

Primitive versions

Helpers

2 declarations