[KinoSearch] Feature request: overloading

webmasters at ctosonline.org webmasters at ctosonline.org
Mon May 18 16:06:52 PDT 2009


On May 18, 2009, at 9:48 AM, Marvin Humphrey wrote:

>> I have a small request: Could classes like KinoSearch::Util::I32Array
>> have arrayref overloading, so I don’t have to call ->to_arrayref or
>> ->to_perl?
>
> There shouldn't be any public APIs which require the user to deal  
> with an
> I32Array.  Presumably you've encountered one in an undocumented  
> function?

TermVector->get_start_offsets, ->get_end_offsets
>
> The way I prefer to solve these kinds of issues is to convert to  
> genuine Perl
> primitives for public APIs.  However, converting certain KS objects  
> can
> potentially be very expensive, so the default binding code has  
> historically
> converted only CharBuf/ByteBuf strings automatically.
>
> With KS almost entirely in C now, though, conversion costs are less  
> of a
> concern -- so I've gone and changed how return values are handled.   
> VArrays
> and Hashes now undergo recursive conversion by default, which should  
> make
> hacking on undocumented features a little easier.  However, I32Array  
> is not
> part of the new regime.
>
> An I32Array isn't really that similar to a Perl array -- it's more  
> like a
> scalar containing packed 32-bit integers.  The memory requirements  
> of VArray,
> Hash, CharBuf, and ByteBuf are roughly similar to their Perl  
> analogues.  But
> an I32Array represented as a Perl array would occupy much more space  
> -- so my
> preference for conversion can only be applied when we can guarantee  
> that
> conversion wouldn't trigger a huge memory bloom.
>
> Overloading I32Array would be awkward, though.  To make overloading  
> work, we'd
> have to have the arrayref-implementing function return a reference  
> to a tied
> object.  I think we might be able to use the main object for that,  
> but that
> requires trickiness along the lines of kino_Doc_to_host in
> xs/KinoSearch/Doc.c.  It's no longer a "small request".  :)

Are you thinking of implementing the tie in C? If we do it in Perl,  
would that simplify things, or does its magic get in the way still on  
the C side?

Father Chrysostomos




More information about the kinosearch mailing list