primitive-0.6: 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.Addr

Contents

Description

Primitive operations on machine addresses

Synopsis

Types

data Addr

A machine address

Constructors

Addr Addr# 

Address arithmetic

nullAddr :: Addr

The null address

plusAddr :: Addr -> Int -> Addr infixl 6

Offset an address by the given number of bytes

minusAddr :: Addr -> Addr -> Int infixl 6

Distance in bytes between two addresses. The result is only valid if the difference fits in an Int.

remAddr :: Addr -> Int -> Int infixl 7

The remainder of the address and the integer.

Element access

indexOffAddr :: Prim a => Addr -> Int -> a

Read a value from a memory position given by an address 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.

readOffAddr :: (Prim a, PrimMonad m) => Addr -> 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.

writeOffAddr :: (Prim a, PrimMonad m) => Addr -> 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

copyAddr

Arguments

:: PrimMonad m 
=> Addr

destination address

-> Addr

source address

-> Int

number of bytes

-> m () 

Copy the given number of bytes from the second Addr to the first. The areas may not overlap.

moveAddr

Arguments

:: PrimMonad m 
=> Addr

destination address

-> Addr

source address

-> Int

number of bytes

-> m () 

Copy the given number of bytes from the second Addr to the first. The areas may overlap.

setAddr :: (Prim a, PrimMonad m) => Addr -> Int -> a -> m ()

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