是什么决定了Devel :: Peek的LEN值

时间:2013-01-17 10:30:55

标签: perl

为什么这里LEN来自Dump 80?

#!/usr/bin/env perl
use warnings;
use strict;
use 5.10.1;
use Devel::Peek;

my $a = 'a';
Dump $a;

print 'Enter an "a": ';
$a = <>;
chomp $a;
Dump $a;

my $b = 'a';
Dump $b;

print 'Enter an "a": ';
my $c = <>;
chomp $c;
Dump $c;

输出:

SV = PV(0x125b090) at 0x127e018
REFCNT = 1
FLAGS = (PADMY,POK,pPOK)
PV = 0x126df80 "a"\0
CUR = 1
LEN = 16
Enter an "a": a
SV = PV(0x125b090) at 0x127e018
REFCNT = 1
FLAGS = (PADMY,POK,pPOK)
PV = 0x126df80 "a"\0
CUR = 1
LEN = 16
SV = PV(0x125b190) at 0x127e0d8
REFCNT = 1
FLAGS = (PADMY,POK,pPOK)
PV = 0x1290da0 "a"\0
CUR = 1
LEN = 16
Enter an "a": a
SV = PV(0x125b1a0) at 0x128f260
REFCNT = 1
FLAGS = (PADMY,POK,pPOK)
PV = 0x1285c70 "a"\0
CUR = 1
LEN = 80

1 个答案:

答案 0 :(得分:3)

因为在你的$c定义中,你从STDIN设置它,解释器可能为该操作预先分配了一些空间,以减少以后必须分配更多空间的可能性。

一般来说,Perl像醉酒的水手一样花费记忆而不是潜在地伤害表现。一旦分配了一些内存,除非你的操作系统内存不足,否则它永远不会被释放。