foundation-0.0.13: Alternative prelude with batteries and no dependencies

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Foundation.Array.Internal

Contents

Description

Give access to Array non public functions which can be used to make certains optimisations.

Most of what is available here has no guarantees of stability. Anything can be removed and changed.

Synopsis

Documentation

data UArray ty

An array of type built on top of GHC primitive.

The elements need to have fixed sized and the representation is a packed contiguous array in memory that can easily be passed to foreign interface

Constructors

UArray !(Offset ty) !(CountOf ty) !(UArrayBackend ty) 

Instances

PrimType ty => IsList (UArray ty) 
(PrimType ty, Eq ty) => Eq (UArray ty) 
Data ty => Data (UArray ty) 
(PrimType ty, Ord ty) => Ord (UArray ty) 
(PrimType ty, Show ty) => Show (UArray ty) 
PrimType ty => Monoid (UArray ty) 
NormalForm (UArray ty) 
PrimType ty => Buildable (UArray ty) 
PrimType ty => Fold1able (UArray ty) 
PrimType ty => Foldable (UArray ty) 
PrimType ty => IndexedCollection (UArray ty) 
PrimType ty => InnerFunctor (UArray ty) 
PrimType ty => Collection (UArray ty) 
PrimType ty => Sequential (UArray ty) 
PrimType ty => Zippable (UArray ty) 
PrimType ty => Copy (UArray ty) 
PrimType a => Hashable (UArray a) 
type Item (UArray ty) = ty 
type Element (UArray ty) = ty 
type Mutable (UArray ty) = MUArray ty 
type Step (UArray ty) = ty 

withPtr :: forall ty prim a. (PrimMonad prim, PrimType ty) => UArray ty -> (Ptr ty -> prim a) -> prim a

copyToPtr

Arguments

:: (PrimType ty, PrimMonad prim) 
=> UArray ty

the source array to copy

-> Ptr ty

The destination address where the copy is going to start

-> prim () 

Copy all the block content to the memory starting at the destination address

recast :: forall a b. (PrimType a, PrimType b) => UArray a -> UArray b

Recast an array of type a to an array of b

a and b need to have the same size otherwise this raise an async exception

Mutable facilities

new :: (PrimMonad prim, PrimType ty) => CountOf ty -> prim (MUArray ty (PrimState prim))

Create a new mutable array of size @n.

When memory for a new array is allocated, we decide if that memory region should be pinned (will not be copied around by GC) or unpinned (can be moved around by GC) depending on its size.

You can change the threshold value used by setting the environment variable HS_FOUNDATION_UARRAY_UNPINNED_MAX.

newPinned :: forall prim ty. (PrimMonad prim, PrimType ty) => CountOf ty -> prim (MUArray ty (PrimState prim))

Create a new pinned mutable array of size @n.

all the cells are uninitialized and could contains invalid values.

All mutable arrays are allocated on a 64 bits aligned addresses

withMutablePtr :: (PrimMonad prim, PrimType ty) => MUArray ty (PrimState prim) -> (Ptr ty -> prim a) -> prim a

Create a pointer on the beginning of the mutable array and call a function f.

The mutable buffer can be mutated by the f function and the change will be reflected in the mutable array

If the mutable array is unpinned, a trampoline buffer is created and the data is only copied when f return.