in reply to Re^2: XS and overload
in thread XS and overload
Well, actually, you can combine both overloading and tying. For instance, if you were developing a vector class:
There is nothing special about tie or overloading methods implemented in XS, you just have to give then the right names in the first case or register them as overload methods with the overload module (well, you will probably need to init the XS part from a BEGIN block, so that the methods are available when you do the use overload ...).my $v = Vector->new(1..10); my $u = Vector->new(11..20); my $w = $u - $v; # overload my $e5 = $w->[5]; # tie
About speed, not too long ago, I did some benchmarks for my Tie::Array::Packed module that implements a tie interface in pure XS for packed arrays, and found that it was around 15 times slower that perl native arrays (a pure perl implementation as provided by Tie::Array::PackedC is around 60 times slower than native arrays). The extra overhead is caused by the method dispatching and because on every call some SVs are created, copied and deallocated which are relatively expensive operations.
On the other hand, comparing a tied array access or an overload operation to a method call, the performance should be quite similar. The only difference is that the tie/overload operation has to perform a magic lookup, something that only requires a few C operations.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: XS and overload
by BrowserUk (Patriarch) on Apr 22, 2006 at 22:05 UTC |