License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
- data UArray ty = UArray !(Offset ty) !(CountOf ty) !(UArrayBackend ty)
- fromForeignPtr :: PrimType ty => (ForeignPtr ty, Int, Int) -> UArray ty
- withPtr :: forall ty prim a. (PrimMonad prim, PrimType ty) => UArray ty -> (Ptr ty -> prim a) -> prim a
- copyToPtr :: (PrimType ty, PrimMonad prim) => UArray ty -> Ptr ty -> prim ()
- recast :: (PrimType a, PrimType b) => UArray a -> UArray b
- toHexadecimal :: PrimType ty => UArray ty -> UArray Word8
- new :: (PrimMonad prim, PrimType ty) => CountOf ty -> prim (MUArray ty (PrimState prim))
- newPinned :: (PrimMonad prim, PrimType ty) => CountOf ty -> prim (MUArray ty (PrimState prim))
- withMutablePtr :: (PrimMonad prim, PrimType ty) => MUArray ty (PrimState prim) -> (Ptr ty -> prim a) -> prim a
Documentation
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
Instances
fromForeignPtr :: PrimType ty => (ForeignPtr ty, Int, Int) -> UArray ty Source #
Create a foreign UArray from foreign memory and given offset/size
No check are performed to make sure this is valid, so this is unsafe.
This is particularly useful when dealing with foreign memory and
ByteString
withPtr :: forall ty prim a. (PrimMonad prim, PrimType ty) => UArray ty -> (Ptr ty -> prim a) -> prim a Source #
Get a Ptr pointing to the data in the UArray.
Since a UArray is immutable, this Ptr shouldn't be to use to modify the contents
If the UArray is pinned, then its address is returned as is, however if it's unpinned, a pinned copy of the UArray is made before getting the address.
:: (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 :: (PrimType a, PrimType b) => UArray a -> UArray b Source #
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)) Source #
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 :: (PrimMonad prim, PrimType ty) => CountOf ty -> prim (MUArray ty (PrimState prim)) Source #
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 Source #
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.