X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlguts.pod;h=c069e8801c35ff4531aba168816092e6f6db1a48;hb=da58a35d3e499cdd492619302eb044ac1841788f;hp=bd681a13dfda2347973ed6c7f6a288ef2abc5818;hpb=b3b6085d10c63109395e1fb03e3cedb8e77ab613;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlguts.pod b/pod/perlguts.pod index bd681a1..c069e88 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -210,6 +210,39 @@ line and all will be well. To free an SV that you've created, call C. Normally this call is not necessary (see L). +=head2 Offsets + +Perl provides the function C to efficiently remove characters +from the beginning of a string; you give it an SV and a pointer to +somewhere inside the the PV, and it discards everything before the +pointer. The efficiency comes by means of a little hack: instead of +actually removing the characters, C sets the flag C +(offset OK) to signal to other functions that the offset hack is in +effect, and it puts the number of bytes chopped off into the IV field +of the SV. It then moves the PV pointer (called C) forward that +many bytes, and adjusts C and C. + +Hence, at this point, the start of the buffer that we allocated lives +at C in memory and the PV pointer is pointing +into the middle of this allocated storage. + +This is best demonstrated by example: + + % ./perl -Ilib -MDevel::Peek -le '$a="12345"; $a=~s/.//; Dump($a)' + SV = PVIV(0x8128450) at 0x81340f0 + REFCNT = 1 + FLAGS = (POK,OOK,pPOK) + IV = 1 (OFFSET) + PV = 0x8135781 ( "1" . ) "2345"\0 + CUR = 4 + LEN = 5 + +Here the number of bytes chopped off (1) is put into IV, and +C helpfully reminds us that this is an offset. The +portion of the string between the "real" and the "fake" beginnings is +shown in parentheses, and the values of C and C reflect +the fake beginning, not the real one. + =head2 What's Really Stored in an SV? Recall that the usual method of determining the type of scalar you have is @@ -1055,7 +1088,7 @@ an C/C pair. Inside such a I the following service is available: -=over +=over 4 =item C @@ -1128,7 +1161,7 @@ provide pointers to the modifiable data explicitly (either C pointers, or Perlish Cs). Where the above macros take C, a similar function takes C. -=over +=over 4 =item C