[Haskell-cafe] Re: "C" buffer suggestions??

Adam Langley agl at imperialviolet.org
Mon Jun 23 17:00:34 EDT 2008

On Mon, Jun 23, 2008 at 1:15 PM, Galchin, Vasili <vigalchin at gmail.com> wrote:
>      I tried to write a test value of Word8 without success. Can you give an example?

I'm not quite sure what you would want in such an example. See [1] for
the malloc function. Then you take the result and wrap it with [2]:
 fp <- mallocBytes nbytes >>= newForeignPtr finalizerFree

When you want to use it, use [3] to unwrap fp and get a raw Ptr Word8.
You can pass these to foreign functions any place they expect a
uint8_t *, char * etc.

[1] http://www.haskell.org/hoogle/hoodoc.cgi?module=Foreign.Marshal.Alloc&name=mallocBytes&mode=func
[2] http://www.haskell.org/hoogle/hoodoc.cgi?module=Foreign.ForeignPtr&name=newForeignPtr&mode=func
[3] http://www.haskell.org/hoogle/hoodoc.cgi?module=Foreign.ForeignPtr&name=withForeignPtr&mode=func

Adam Langley agl at imperialviolet.org http://www.imperialviolet.org

More information about the Haskell-Cafe mailing list