HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleprimitive-0.9.1.0Haskell2010

Data.Primitive.Ptr

Primitive operations on machine addresses.

  • 1 type
  • 11 values

Types

1 declaration
datadata Ptr a
#

A value of type Ptr a represents a pointer to an object, or an array of objects, which may be marshalled to or from Haskell values of type a.

The type a will often be an instance of class Storable which provides the marshalling operations. However this is not essential, and you can provide your own operations to access the pointer. For example you might write small foreign functions to get or set the fields of a C struct.

Constructors

Instances21NFData1, IArray, Generic1, Data, Show, Foldable, …

Address arithmetic

3 declarations
valuenullPtr :: Ptr a
#

The constant nullPtr contains a distinguished value of Ptr that is not associated with a valid memory location.

valuesubtractPtr :: Prim a => Ptr a -> Ptr a -> Int
#

Subtract a pointer from another pointer. The result represents the number of elements of type a that fit in the contiguous memory range bounded by these two pointers.

Element access

3 declarations
valueindexOffPtr :: Prim a => Ptr a -> Int -> a
#

Read a value from a memory position given by a pointer and an offset. The memory block the address refers to must be immutable. The offset is in elements of type a rather than in bytes.

valuereadOffPtr :: (Prim a, PrimMonad m) => Ptr a -> Int -> m a
#

Read a value from a memory position given by an address and an offset. The offset is in elements of type a rather than in bytes.

valuewriteOffPtr :: (Prim a, PrimMonad m) => Ptr a -> Int -> a -> m ()
#

Write a value to a memory position given by an address and an offset. The offset is in elements of type a rather than in bytes.

Block operations

5 declarations
valuecopyPtr
  1. :: (PrimMonad m, Prim a)
  2. => Ptr a

    destination pointer

  3. -> Ptr a

    source pointer

  4. -> Int

    number of elements

  5. -> m ()
#

Copy the given number of elements from the second Ptr to the first. The areas may not overlap.

valuemovePtr
  1. :: (PrimMonad m, Prim a)
  2. => Ptr a

    destination pointer

  3. -> Ptr a

    source pointer

  4. -> Int

    number of elements

  5. -> m ()
#

Copy the given number of elements from the second Ptr to the first. The areas may overlap.

valuesetPtr :: (Prim a, PrimMonad m) => Ptr a -> Int -> a -> m ()
#

Fill a memory block with the given value. The length is in elements of type a rather than in bytes.

valuecopyPtrToMutablePrimArray
  1. :: (PrimMonad m, Prim a)
  2. => MutablePrimArray (PrimState m) a

    destination array

  3. -> Int

    destination offset

  4. -> Ptr a

    source pointer

  5. -> Int

    number of elements

  6. -> m ()
#

Copy from a pointer to a mutable primitive array. The offset and length are given in elements of type a. This function assumes that the Prim instance of a agrees with the Storable instance.

Note: this function does not do bounds or overlap checking.

valuecopyPtrToMutableByteArray
  1. :: (PrimMonad m, Prim a)
  2. => MutableByteArray (PrimState m)

    destination array

  3. -> Int

    destination offset given in elements of type a

  4. -> Ptr a

    source pointer

  5. -> Int

    number of elements

  6. -> m ()
#

Copy from an unmanaged pointer address to a byte array. These must not overlap. The offset and length are given in elements, not in bytes.

Note: this function does not do bounds or overlap checking.