What I'm seeking is the lowest cost way to provide direct access to memory (mapped to a file) from Perl code.
Right off the bat, that eliminates magic. Let's compare
tosubstr($s, $pos, $len) = $x;
substr($s, $pos, $len, $x);
This is what occurs in the assignment version:
In contrast, the following occurs for the 4-arg version:
None of the extra steps in the first version are particularly cheap either.
But let's say you're ok with the overhead.
it falls foul of the substr limitations you helped identify earlier in the week which means that you cannot use offsets ≥2GB.
Then substr magic is definitely not acceptable, since suffers from the same problem.
int Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg) { STRLEN len; SV * const lsv = LvTARG(sv); const char * const tmps = SvPV_const(lsv,len); I32 offs = LvTARGOFF(sv); I32 rem = LvTARGLEN(sv); ... } int Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg) { dVAR; STRLEN len; const char * const tmps = SvPV_const(sv, len); SV * const lsv = LvTARG(sv); I32 lvoff = LvTARGOFF(sv); I32 lvlen = LvTARGLEN(sv); ... }
Actually, the more I think about this, I think you may have been half right back there when you talked about lvalue subs
I looked in perlxs quickly, and I didn't see anything about this. Maybe adding one of the following to the associated .pm will work:
sub xs_func1 :lvalue; sub xs_func2 :lvalue;
or
use attributes (); for (qw( xs_func1 xs_func2 )) { no strict 'refs'; attributes->import(__PACKAGE__, \&{$_}, 'lvalue'); }
And in any case, incrementing bytes isn't particularly useful
Sounds like you want your function to return numbers.
my $mmap = $class->new( ..., endianess => ENDIAN_NATIVE ); ++( $mmap->uint8(0x1234) );
In reply to Re: XS: SvPVLV examples?
by ikegami
in thread XS: SvPVLV examples?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |