[clean-list] htoclean question

John Small jwebsmall at cox.net
Mon Mar 28 19:37:12 MEST 2005


The FFI (foreign function interface) allows you to pass
CleanString's from C returning them to Clean.

But these CleanString's are then immediately copied
bringing the string data back across the garbage collecting
perimeter within the purview of Clean's memory
management.  From the htoclean documentation:

    When a CleanString is returned from C, a copy
    of the string will be created in the Clean heap, and
    this copy will be used by Clean. If the string was
    allocated in C, for example using malloc, it should
    be deallocated in C when it no longer used, it is not
    automatically deallocated by Clean. 

Thus a C string returned from an existing dynamic link library
must first be rewrapped as a CleanString in a second layer C
wrapper for the DLL and finally copied a second time by Clean.
So in effect I'm triple buffering every string crossing the FFI frontier
in bound to Clean land.

My question is can htoclean and the Clean runtime be modified
to receive a returned C string copying it only once on
the fly directly into the final Clean string within the garbaging
collecting perimeter?

I want to write a FFI to the MySQL database dynamic link library
and I'm forced to wrap another C layer around it and handle the
malloc/frees simply for this third buffer and performance suffers.

Before I take time to dig into fclc.dcl/icl  I just wanted to know if this
is a mission impossible.

Thanks.

John

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.science.ru.nl/pipermail/clean-list/attachments/20050328/9585baef/attachment.html


More information about the clean-list mailing list