primitive-0.7.4.0: Primitive memory-related operations
Copyright (c) Roman Leshchinskiy 2009-2012
License BSD-style
Maintainer Roman Leshchinskiy <rl@cse.unsw.edu.au>
Portability non-portable
Safe Haskell None
Language Haskell2010

Data.Primitive.Ptr

Description

Primitive operations on machine addresses.

Since: 0.6.4.0

Synopsis

Types

data Ptr a Source #

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

Ptr Addr#

Instances

Instances details
NFData1 Ptr

Since: deepseq-1.4.3.0

Instance details

Defined in Control.DeepSeq

Methods

liftRnf :: (a -> ()) -> Ptr a -> () Source #

Generic1 ( URec ( Ptr ()) :: k -> Type )

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Associated Types

type Rep1 ( URec ( Ptr ())) :: k -> Type Source #

Methods

from1 :: forall (a :: k0). URec ( Ptr ()) a -> Rep1 ( URec ( Ptr ())) a Source #

to1 :: forall (a :: k0). Rep1 ( URec ( Ptr ())) a -> URec ( Ptr ()) a Source #

Eq ( Ptr a)

Since: base-2.1

Instance details

Defined in GHC.Ptr

Data a => Data ( Ptr a)

Since: base-4.8.0.0

Instance details

Defined in Data.Data

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Ptr a -> c ( Ptr a) Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( Ptr a) Source #

toConstr :: Ptr a -> Constr Source #

dataTypeOf :: Ptr a -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( Ptr a)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( Ptr a)) Source #

gmapT :: ( forall b. Data b => b -> b) -> Ptr a -> Ptr a Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Ptr a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Ptr a -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Ptr a -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Ptr a -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Ptr a -> m ( Ptr a) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Ptr a -> m ( Ptr a) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Ptr a -> m ( Ptr a) Source #

Ord ( Ptr a)

Since: base-2.1

Instance details

Defined in GHC.Ptr

Show ( Ptr a)

Since: base-2.1

Instance details

Defined in GHC.Ptr

Foldable ( UAddr :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Traversable ( UAddr :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Traversable

Storable ( Ptr a)

Since: base-2.1

Instance details

Defined in Foreign.Storable

NFData ( Ptr a)

Since: deepseq-1.4.2.0

Instance details

Defined in Control.DeepSeq

Methods

rnf :: Ptr a -> () Source #

Prim ( Ptr a) Source #
Instance details

Defined in Data.Primitive.Types

Functor ( URec ( Ptr ()) :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> URec ( Ptr ()) a -> URec ( Ptr ()) b Source #

(<$) :: a -> URec ( Ptr ()) b -> URec ( Ptr ()) a Source #

Eq ( URec ( Ptr ()) p)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Ord ( URec ( Ptr ()) p)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Generic ( URec ( Ptr ()) p)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Associated Types

type Rep ( URec ( Ptr ()) p) :: Type -> Type Source #

data URec ( Ptr ()) (p :: k)

Used for marking occurrences of Addr#

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

data URec ( Ptr ()) (p :: k) = UAddr { }
type Rep1 ( URec ( Ptr ()) :: k -> Type )
Instance details

Defined in GHC.Generics

type Rep ( URec ( Ptr ()) p)
Instance details

Defined in GHC.Generics

Address arithmetic

nullPtr :: Ptr a Source #

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

advancePtr :: forall a. Prim a => Ptr a -> Int -> Ptr a Source #

Offset a pointer by the given number of elements.

subtractPtr :: forall a. Prim a => Ptr a -> Ptr a -> Int Source #

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

indexOffPtr :: Prim a => Ptr a -> Int -> a Source #

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.

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

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.

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

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

copyPtr Source #

Arguments

:: forall m a. ( PrimMonad m, Prim a)
=> Ptr a

destination pointer

-> Ptr a

source pointer

-> Int

number of elements

-> m ()

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

movePtr Source #

Arguments

:: forall m a. ( PrimMonad m, Prim a)
=> Ptr a

destination pointer

-> Ptr a

source pointer

-> Int

number of elements

-> m ()

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

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

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

copyPtrToMutablePrimArray Source #

Arguments

:: forall m a. ( PrimMonad m, Prim a)
=> MutablePrimArray ( PrimState m) a

destination array

-> Int

destination offset

-> Ptr a

source pointer

-> Int

number of elements

-> 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.

copyPtrToMutableByteArray Source #

Arguments

:: forall m a. ( PrimMonad m, Prim a)
=> MutableByteArray ( PrimState m)

destination array

-> Int

destination offset given in elements of type a

-> Ptr a

source pointer

-> Int

number of elements

-> 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.