[KinoSearch] Feature request: overloading

Marvin Humphrey marvin at rectangular.com
Mon May 18 09:48:02 PDT 2009


> 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?

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".  :)

Marvin Humphrey



More information about the kinosearch mailing list