incubator-lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <>
Subject Re: Creation and Destruction
Date Sat, 14 Oct 2006 05:03:08 GMT

On Oct 13, 2006, at 6:42 AM, Peter Karman wrote:

> David Balmain scribbled on 10/13/06 1:21 AM:
>> I don't know how much of Ferret's binding code you've looked at but
>> you may have noticed a lot of my structs have a ref_cnt variable.  
>> That
>> way, every time a struct gets wrapped in a ruby object, it's ref_cnt
>> is incremented. When the object goes out of scope and is garbage
>> collected the ref_cnt is decremented (and the object deleted if
>> ref_cnt = 0). I think as far as supporting multiple languages like we
>> are attempting to do with Lucy, this is the easiest way to go, since
>> it should work for all languages.

> fwiw, I have used the above approach in Perl myself. I just increm/ 
> decrem the refcnt in XS (Perl) space, in the DESTROY method.

I like this approach better, and I've now changed KinoSearch to use it.

One minor theoretical problem with subclassing.  Say you have a  
struct that holds a TermDocs.

typedef struct lucy_SomeStruct {
     struct lucy_TermDocs *term_docs;
     /* ... */
} lucy_SomeStruct;

A Perl object created off of that has to take the class  
"Lucy::Index::TermDocs", rather than "Lucy::Index::SegTermDocs" or  
"Lucy::Index::MultiTermDocs".  That's not quite right.

/* This is an XS binding */
     lucy_SomeStruct *self;
     RETVAL = self->term_docs;

However, you can only fake OOP so well with C, and this limitation  
hasn't triggered any glitches yet.  We'll see what happens when I  
port IndexReader, SegReader, and MultiReader to C -- they'll all  
appear to be "IndexReader" from Perl-space.  Dunno if that will break  

I also had to jettison a scheme I'd devised for generalizing object- 
method callbacks to [your_language_here], but that might be for the  
best. :)

Marvin Humphrey
Rectangular Research

View raw message