[Haskell-cafe] carry "state" around ....
Galchin, Vasili
vigalchin at gmail.com
Mon Jul 21 00:59:21 EDT 2008
Thank you Duncan for your example. I will also read the RSA code.
Regards, Vasili
On Sun, Jul 20, 2008 at 6:51 AM, Duncan Coutts <duncan.coutts at worc.ox.ac.uk>
wrote:
>
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080720/c6b48d50/attachment.htm
More information about the Haskell-Cafe
mailing list