carray- A C-compatible array library.

Safe HaskellSafe-Infered




This module provides both the mutable IOCArray which uses pinned memory on the GC'd heap. Elements are stored according to the class Storable. You can obtain a pointer to the array contents to manipulate elements from languages like C.

IOCArray is 16-byte aligned by default. If you create a IOCArray with unsafeForeignPtrToIOCArray then it may not be aligned. This will be an issue if you intend to use SIMD instructions.

IOCArray is equivalent to StorableArray and similar to IOUArray but slower. IOCArray has O(1) versions of unsafeFreeze and unsafeThaw when converting to/from CArray.


IOCArray type

data IOCArray i e Source

Absolutely equivalent representation, but used for the mutable interface.


Foreign support

withIOCArray :: IOCArray i e -> (Ptr e -> IO a) -> IO aSource

touchIOCArray :: IOCArray i e -> IO ()Source

If you want to use it afterwards, ensure that you touchCArray after the last use of the pointer, so the array is not freed too early.

unsafeForeignPtrToIOCArray :: Ix i => ForeignPtr e -> (i, i) -> IO (IOCArray i e)Source

O(1) Construct a CArray from an arbitrary ForeignPtr. It is the caller's responsibility to ensure that the ForeignPtr points to an area of memory sufficient for the specified bounds.

The overloaded mutable array interface