On Sat, 2008-07-19 at 23:55 -0500, Galchin, Vasili wrote:
> yes Duncan I am trying to pass-by-value. I am familiar with
> ForeignPtr; however, I don't comprehend what you and Brandon are
> suggesting to do. Could either of you provide a code illustration or
> point at existing code to illustrate your approach?

Take a look at John Meacham's RSA example.

So at the moment you're using using Storable and a Haskell record, say:

data AIOCB = AIOCB { 
    ...
  }

and we're suggesting instead:

newtype AIOCB = AIOCB (ForeignPtr AIOCB)

then to access a member use hsc2hs:

getBlah :: AIOCB -> IO Blah
getBlah (AIOCB fptr) =
  withForeignPtr fptr $ \ptr -> {# peek aiocb,blah #} ptr

So you only access the parts you need and keep the aiocb C struct
allocated on the heap (use mallocForeignPtr).

Duncan

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to