[gambit-list] On FFI argument and buffer memory handling

Mikael More mikael.more at gmail.com
Wed Oct 8 18:50:37 EDT 2008


Hi!
I suppose these questions better be directed to Marc:
a)
On many occassions, FFI:s need to pass external libraries structures. These
are variables passed by value (ints, floats, bools), and variables passed as
pointers, that is, strings and structures.

Two questions:

First off, I presume that UTF-8-string argument values passed to a c-lambda
are by default allocated until function return. How can one make so that
such an argument value continues to exist after the C function returns (i.e.
increase reference count)? At the time one wants to discard the string, how
is that done (i.e. decrease reference count)?

Second, on many occasions, one needs malloc/free functionality in FFI code.
Do you recommend one to use some Gambit-internal function to get the
functional equivalent, or to go with a malloc such as tcmalloc?

b)
Do c-lambda invocation require a trampoline, so that there's a trampoline
cost involved in each Scheme-to-C call? (Each taking ~0.5*10^-8 seconds,
afaik)

c)
Is there one particular practice you recommend for FFI functions to return
multiple return values, in a performant way? Can you give a code example
that returns bool, unsigned 32- and 64-bit integer, char* containing UTF-8
string, and byte buffer returned as u8vector?

Thanks
Mikael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20081009/dc4f859a/attachment.htm>


More information about the Gambit-list mailing list