[BioRuby] Ruby & D shared libraries
Pjotr Prins
pjotr.public14 at thebird.nl
Tue Apr 10 20:54:54 UTC 2012
>From the blog: (Actually, I would be glad to hear any ideas how to get
rid of this extra copying and return just immutable(char)*[] because
its layout is the same#)
You can enforce a zero byte at the end of the D String, at the point
of initialization. That would allow passing s.ptr. Alternatively study
Ruby internals - Ruby strings are not zero terminated either, the
structure is much like D's... And FFI copies the data in/out of the
Ruby String object anyway - I am pretty certain.
It sounds costly, but actually, the real cost of FFI is not in data
copying, but rather in Ruby object creation (and destruction). To
avoid death by object creation, the Narray module may give some clues.
Narray maps Ruby array structures directly on C structures. At least,
last time I looked.
But really, let's not optimize prematurely. A smart API does not need
to pump much data...
Pj.
More information about the BioRuby
mailing list