{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, RoleAnnotations #-}{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------- |-- Module : Data.Array.Storable.Internals-- Copyright : (c) The University of Glasgow 2011-- License : BSD-style (see the file libraries/base/LICENSE)---- Maintainer : libraries@haskell.org-- Stability : experimental-- Portability : non-portable (uses Data.Array.MArray)---- Actual implementation of "Data.Array.Storable".---- @since 0.4.0.0-----------------------------------------------------------------------------moduleData.Array.Storable.Internals(StorableArray (..),withStorableArray ,touchStorableArray ,unsafeForeignPtrToStorableArray ,)whereimportData.Array.Base importData.Array.MArray importForeignhiding(newArray)-- |The array typedataStorableArray i e =StorableArray !i !i Int!(ForeignPtre )-- Both parameters have class-based invariants. See also #9220.typeroleStorableArraynominalnominalinstanceStorablee =>MArray StorableArray e IOwheregetBounds (StorableArray l u __)=return(l ,u )getNumElements (StorableArray _l _u n _)=returnn newArray (l ,u )initialValue =dofp <-mallocForeignPtrArraysize withForeignPtrfp $\a ->sequence_[pokeElemOffa i initialValue |i <-[0..size -1]]return(StorableArray l u size fp )wheresize =rangeSize(l ,u )unsafeNewArray_ (l ,u )=doletn =rangeSize(l ,u )fp <-mallocForeignPtrArrayn return(StorableArray l u n fp )newArray_ =unsafeNewArray_ unsafeRead (StorableArray ___fp )i =withForeignPtrfp $\a ->peekElemOffa i unsafeWrite (StorableArray ___fp )i e =withForeignPtrfp $\a ->pokeElemOffa i e -- |The pointer to the array contents is obtained by 'withStorableArray'.-- The idea is similar to 'ForeignPtr' (used internally here).-- The pointer should be used only during execution of the 'IO' action-- retured by the function passed as argument to 'withStorableArray'.withStorableArray::StorableArray i e ->(Ptre ->IOa )->IOa withStorableArray (StorableArray ___fp )f =withForeignPtrfp f -- |If you want to use it afterwards, ensure that you-- 'touchStorableArray' after the last use of the pointer,-- so the array is not freed too early.touchStorableArray::StorableArray i e ->IO()touchStorableArray (StorableArray ___fp )=touchForeignPtrfp -- |Construct a 'StorableArray' 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.unsafeForeignPtrToStorableArray::Ixi =>ForeignPtre ->(i ,i )->IO(StorableArray i e )unsafeForeignPtrToStorableArray p (l ,u )=return(StorableArray l u (rangeSize(l ,u ))p )

AltStyle によって変換されたページ (->オリジナル) /