[Haskell-cafe] Are FunPtr's stable? (was: how to write an haskell binding)

Brian Hulley brianh at metamilk.com
Tue Jun 27 14:39:17 EDT 2006

Bulat Ziganshin wrote:
> Hello Brian,
> Tuesday, June 27, 2006, 2:43:15 AM, you wrote:
>> achieve a goal. One other thing to bear in mind is that foreign
>> calls are extremely slow, so for example it is much faster to use the
>> Foreign.Marshal.Array and Foreign.C.String functions to allocate and
>> populate a temporary array with the contents of a list, and send the
>> pointer to this array to C with one foreign call, than to send each
>> element of the list with multiple foreign calls (eg to paste only
>> 19K of text from the Windows clipboard to my app took over 1
>> minute!!!
> he-he-he :)  just add "unsafe" specifier:

Thanks Bulat! It turns out nearly every foreign function I'm using doesn't 
make callbacks into Haskell so can be marked "unsafe" so your solution has 
saved me an enormous amount of refactoring... :-)

On a related note, as I was reading the FFI specification again, I can't 
find any mention of whether or not FunPtr's are stable with respect to 
garbage collection. I'm assuming they are but am I correct?

Thanks, Brian.

Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.


More information about the Haskell-Cafe mailing list