As for the additional memory, when you Devel::Peek::Dump() the reference (with a shorter string), you can see that a PV has been created after having accessed the string (via "magic"). My first guess would be this is some caching behavior to increase performance with repeated accesses.
use Devel::Peek;
$v = chr(0); $v x= 50;
$r = \substr $v, 25;
Dump $r;
vec( $v, 25, 8 ) = 0b10101010;
print vec( $$r, $_, 1 ) for 0..7;
Dump $r;
__END__
SV = IV(0x7991e0) at 0x7991f0
REFCNT = 1
FLAGS = (ROK)
RV = 0x771998
SV = PVLV(0x7a1ce0) at 0x771998
REFCNT = 1
FLAGS = (GMG,SMG)
IV = 0
NV = 0
PV = 0
MAGIC = 0x7914f0
MG_VIRTUAL = &PL_vtbl_substr
MG_TYPE = PERL_MAGIC_substr(x)
TYPE = x
TARGOFF = 25
TARGLEN = 25
TARG = 0x7991c0
SV = PV(0x76fc20) at 0x7991c0
REFCNT = 2
FLAGS = (POK,pPOK)
PV = 0x7a4f50 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
+0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"\0
CUR = 50
LEN = 56
0
1
0
1
0
1
0
1
SV = IV(0x7991e0) at 0x7991f0
REFCNT = 1
FLAGS = (ROK)
RV = 0x771998
SV = PVLV(0x7a1ce0) at 0x771998
REFCNT = 1
FLAGS = (GMG,SMG,pPOK)
IV = 0
NV = 0
PV = 0x7917e0 "\252\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
+0"\0 # <---
CUR = 25
LEN = 32
MAGIC = 0x7914f0
MG_VIRTUAL = &PL_vtbl_substr
MG_TYPE = PERL_MAGIC_substr(x)
TYPE = x
TARGOFF = 25
TARGLEN = 25
TARG = 0x7991c0
SV = PV(0x76fc20) at 0x7991c0
REFCNT = 2
FLAGS = (POK,pPOK)
PV = 0x7a4f50 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
+0\252\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"\0
CUR = 50
LEN = 56
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|