[Haskell-cafe] About pointer taken by C lib in FFI.

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Mon Jan 14 18:28:23 UTC 2019


Thanks. I was meant to ask ForeignPtr as well.

On Mon, Jan 14, 2019 at 6:59 AM Sylvain Henry <sylvain at haskus.fr> wrote:
>
> Hi,
>
> Ptr has no finalizer: you have to explicitly free the attached memory if
> necessary.
>
> You can use ForeignPtr to associate finalizers to a pointer: finalizers
> are functions that are called when the ForeignPtr object is to be
> collected by the GC. GHC can't track if the pointer is still stored/used
> by the C lib though.
>
> Hope that helps,
> Sylvain
>
>
> On 12/01/2019 07:16, Magicloud Magiclouds wrote:
> > Hi,
> >
> > Say I have some data, and `poke` into a Ptr. Then I pass the Ptr to
> > some function in C lib. The C lib stores the Ptr somewhere to use
> > later.
> >
> > My question is, how does GHC handle the finalizing of the Ptr? Does it
> > track the "used by foreign lib"?
> >
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.



-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.


More information about the Haskell-Cafe mailing list