[Haskell-cafe] MutableByteArray as a Ptr
Joel Reymont
joelr1 at gmail.com
Sat Oct 8 03:33:29 EDT 2005
This is no longer an issue as I found how to read and write Float and
Double at the link below
http://www.n-heptane.com/nhlab/repos/NewBinary/Tests/BinDouble.hs
Originally, I was looking to get a chunk of memory using getByteArray
from NewBinary.Binary and read a Storable after converting the array
to a pointer.
getByteArray :: BinHandle -> Int -> IO ByteArray
getByteArray bh (I# sz) = do
(MBA arr) <- newByteArray sz
let loop n
| n ==# sz = return ()
| otherwise = do
w <- getByte bh
writeByteArray arr n w
loop (n +# 1#)
loop 0#
freezeByteArray arr
Thanks, Joel
On Oct 8, 2005, at 4:49 AM, Donald Bruce Stewart wrote:
> Try it and see.. I think I have indeed done this in an old version of
> Yi. However, it sounds a bit iffy, and there's no reason not to use a
> ForeignPtr-ified malloc'd chunk of memory.
--
http://wagerlabs.com/idealab
More information about the Haskell-Cafe
mailing list