primitive-0.6.4.0: Primitive memory-related operations

Copyright(c) Roman Leshchinskiy 2009-2012
LicenseBSD-style
MaintainerRoman Leshchinskiy <rl@cse.unsw.edu.au>
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Primitive.Ptr

Contents

Description

Primitive operations on machine addresses

Since: 0.6.4.0

Synopsis

Types

data 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

Ptr Addr# 

Instances

Generic1 k (URec k (Ptr ())) 

Associated Types

type Rep1 (URec k (Ptr ())) (f :: URec k (Ptr ()) -> *) :: k -> * #

Methods

from1 :: f a -> Rep1 (URec k (Ptr ())) f a #

to1 :: Rep1 (URec k (Ptr ())) f a -> f a #

Eq (Ptr a) 

Methods

(==) :: Ptr a -> Ptr a -> Bool #

(/=) :: Ptr a -> Ptr a -> Bool #

Data a => Data (Ptr a)

Since: 4.8.0.0

Methods

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

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

toConstr :: Ptr a -> Constr #

dataTypeOf :: Ptr a -> DataType #

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

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

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

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

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

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

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

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

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

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

Ord (Ptr a) 

Methods

compare :: Ptr a -> Ptr a -> Ordering #

(<) :: Ptr a -> Ptr a -> Bool #

(<=) :: Ptr a -> Ptr a -> Bool #

(>) :: Ptr a -> Ptr a -> Bool #

(>=) :: Ptr a -> Ptr a -> Bool #

max :: Ptr a -> Ptr a -> Ptr a #

min :: Ptr a -> Ptr a -> Ptr a #

Show (Ptr a)

Since: 2.1

Methods

showsPrec :: Int -> Ptr a -> ShowS #

show :: Ptr a -> String #

showList :: [Ptr a] -> ShowS #

Storable (Ptr a)

Since: 2.1

Methods

sizeOf :: Ptr a -> Int #

alignment :: Ptr a -> Int #

peekElemOff :: Ptr (Ptr a) -> Int -> IO (Ptr a) #

pokeElemOff :: Ptr (Ptr a) -> Int -> Ptr a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Ptr a) #

pokeByteOff :: Ptr b -> Int -> Ptr a -> IO () #

peek :: Ptr (Ptr a) -> IO (Ptr a) #

poke :: Ptr (Ptr a) -> Ptr a -> IO () #

Prim (Ptr a) Source # 
Functor (URec * (Ptr ())) 

Methods

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

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

Foldable (URec * (Ptr ())) 

Methods

fold :: Monoid m => URec * (Ptr ()) m -> m #

foldMap :: Monoid m => (a -> m) -> URec * (Ptr ()) a -> m #

foldr :: (a -> b -> b) -> b -> URec * (Ptr ()) a -> b #

foldr' :: (a -> b -> b) -> b -> URec * (Ptr ()) a -> b #

foldl :: (b -> a -> b) -> b -> URec * (Ptr ()) a -> b #

foldl' :: (b -> a -> b) -> b -> URec * (Ptr ()) a -> b #

foldr1 :: (a -> a -> a) -> URec * (Ptr ()) a -> a #

foldl1 :: (a -> a -> a) -> URec * (Ptr ()) a -> a #

toList :: URec * (Ptr ()) a -> [a] #

null :: URec * (Ptr ()) a -> Bool #

length :: URec * (Ptr ()) a -> Int #

elem :: Eq a => a -> URec * (Ptr ()) a -> Bool #

maximum :: Ord a => URec * (Ptr ()) a -> a #

minimum :: Ord a => URec * (Ptr ()) a -> a #

sum :: Num a => URec * (Ptr ()) a -> a #

product :: Num a => URec * (Ptr ()) a -> a #

Traversable (URec * (Ptr ())) 

Methods

traverse :: Applicative f => (a -> f b) -> URec * (Ptr ()) a -> f (URec * (Ptr ()) b) #

sequenceA :: Applicative f => URec * (Ptr ()) (f a) -> f (URec * (Ptr ()) a) #

mapM :: Monad m => (a -> m b) -> URec * (Ptr ()) a -> m (URec * (Ptr ()) b) #

sequence :: Monad m => URec * (Ptr ()) (m a) -> m (URec * (Ptr ()) a) #

Eq (URec k (Ptr ()) p) 

Methods

(==) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

(/=) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

Ord (URec k (Ptr ()) p) 

Methods

compare :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Ordering #

(<) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

(<=) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

(>) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

(>=) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

max :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> URec k (Ptr ()) p #

min :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> URec k (Ptr ()) p #

Generic (URec k (Ptr ()) p) 

Associated Types

type Rep (URec k (Ptr ()) p) :: * -> * #

Methods

from :: URec k (Ptr ()) p -> Rep (URec k (Ptr ()) p) x #

to :: Rep (URec k (Ptr ()) p) x -> URec k (Ptr ()) p #

data URec k (Ptr ())

Used for marking occurrences of Addr#

Since: 4.9.0.0

data URec k (Ptr ()) = UAddr {}
type Rep1 k (URec k (Ptr ())) 
type Rep1 k (URec k (Ptr ())) = D1 k (MetaData "URec" "GHC.Generics" "base" False) (C1 k (MetaCons "UAddr" PrefixI True) (S1 k (MetaSel (Just Symbol "uAddr#") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (UAddr k)))
type Rep (URec k (Ptr ()) p) 
type Rep (URec k (Ptr ()) p) = D1 * (MetaData "URec" "GHC.Generics" "base" False) (C1 * (MetaCons "UAddr" PrefixI True) (S1 * (MetaSel (Just Symbol "uAddr#") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (UAddr *)))

Address arithmetic

nullPtr :: Ptr a #

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

:: (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

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

destination address

-> Ptr a

source address

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

:: (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 is only available when building with GHC 7.8 or newer.