-----------------------------------------------------------------------------
---
+-- |
-- Module : Data.Array.Storable
-- Copyright : (c) The University of Glasgow 2001
--- License : BSD-style (see the file libraries/core/LICENSE)
+-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
-- Portability : non-portable
--
--- $Id: Storable.hs,v 1.2 2001/07/04 10:51:09 simonmar Exp $
---
-- A storable array is an IO-mutable array which stores its
-- contents in a contiguous memory block living in the C
-- heap. Elements are stored according to the class Storable.
instance Storable e => MArray StorableArray e IO where
newArray (l,u) init = do
- a <- mallocArray size
- sequence_ [pokeElemOff a i init | i <- [0..size-1]]
- fp <- newForeignPtr a (free a)
+ fp <- mallocForeignPtrArray size
+ withForeignPtr fp $ \a ->
+ sequence_ [pokeElemOff a i init | i <- [0..size-1]]
return (StorableArray l u fp)
where
size = rangeSize (l,u)
newArray_ (l,u) = do
- a <- mallocArray (rangeSize (l,u))
- fp <- newForeignPtr a (free a)
+ fp <- mallocForeignPtrArray (rangeSize (l,u))
return (StorableArray l u fp)
unsafeRead (StorableArray _ _ fp) i =