匿名数组的内存地址自然被perl重用。这个例子说明,他们两个地址之间的周期为空数组:为什么Perl会按照这种模式重新分配内存?
$ perl -E "say [] for (1..6)"
ARRAY(0x37b23c)
ARRAY(0x37b28c)
ARRAY(0x37b23c)
ARRAY(0x37b28c)
ARRAY(0x37b23c)
ARRAY(0x37b28c)
我想到了为什么它不能立即重新分配内存的一些理论,当我发现周期并不总是两个地址长。以下示例的周期为3和4.
$ perl -E "say [0] for (1..6)"
ARRAY(0x39b23c)
ARRAY(0x39b2ac)
ARRAY(0x39b28c)
ARRAY(0x39b23c)
ARRAY(0x39b2ac)
ARRAY(0x39b28c)
$ perl -E "say [0,0] for (1..6)"
ARRAY(0x64b23c)
ARRAY(0x64b2cc)
ARRAY(0x64b2ac)
ARRAY(0x64b28c)
ARRAY(0x64b23c)
ARRAY(0x64b2cc)
是什么导致了这种内存管理特性?
你为什么在意? – 2011-04-23 15:49:40
@Jonathan,我在执行模微积分;) 好奇心。 – Tim 2011-04-23 15:52:26
您应该阅读'perldoc perlguts'并加入Perl Porters的邮件列表http://lists.perl.org/list/perl5-porters.html – shawnhcorey 2011-04-23 17:04:03