[Haskell-cafe] ByteString FFI
Donald Bruce Stewart
dons at cse.unsw.edu.au
Mon Nov 13 01:46:48 EST 2006
> On Mon, 13 Nov 2006, Donald Bruce Stewart wrote:
> > And for custom data (not just C strings), if the withCString* functions
> > don't quite fit, you can always pack the foreign Ptr into a ByteString
> > by stepping inside the ByteString constructor:
> > http://www.haskell.org/haskellwiki/Wc#Going_via_C
> That's actually what I tried first, but in this particular situation
> (ghc-6.4.1 / fps-0.7), PS apparently isn't exported?
Right, you'll want to grab the soon-to-be-tagged fps 0.8, which matches
that provided with ghc 6.6. It's in the darcs repo.
> The CStringLen approach works, except that the allocated data doesn't
> get garbage-collected. Just for the sake of experiment I tried a regular
> CString with packMallocCString, and that didn't leak nearly as much memory -
> but still some, in a simple loop where "pack" doesn't leak anything.
More information about the Haskell-Cafe