On 17/06/2015 05:11, Marvin Humphrey wrote:
You mean using a struct RObject as CFISH_OBJ_HEAD similar to what we plan
for the Python bindings? Whether this works depends on how Ruby allocates
and deallocates memory but I wouldn't be surprised if it turns out to be
infeasible.

Yep, that's the case. :(  That's frustrating -- having to allocate a new Ruby
object wrapper every time that Clownfish sends an object into Ruby space
annoys me.  Since Ruby's GC actually watches the C stack, it would have been
an opportunity to demonstrate that Clownfish was flexible enough to work
within both a refcounting model and a tracing GC model while keeping the
object lifetimes coordinated.

Even if it works, embedding RObject in CFISH_OBJ_HEAD blows up the size of every Clownfish object by a considerable amount. I count five machine words (40 bytes on 64-bit) in RObject:

    https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h

With Python, the situation is much better. PyObject only contains two words, and one of them is a refcount that can be reused by Clownfish.

I think allocating a Ruby wrapper for every Clownfish object passed to Ruby space isn't too bad.

Another approach that we already discussed is to cache the Ruby VALUE in cfish_Obj, and keep a list of all these objects in some kind of registry. During GC, the registry could mark all the wrappers as alive.

    http://s.apache.org/cfish-gc

Here's a sketch of how it could work:

    https://gist.github.com/nwellnhof/8daf2871fda012fc23c6

Which approach is more performant depends on the application.

Also, this is only useful for subclassing Clownfish classes from the host
language. If we have some kind of interface support, we'll probably want to
remove this ability anyway. It doesn't make sense to have core features that
are only supported by a subset of host languages.

This is what you described in the thread "Interface-based callbacks for Perl
bindings", right?

     http://markmail.org/message/nauw3psvuta7myn4

Yes. This design is based on abstract classes but interfaces would work the 
same.

Nick

Reply via email to