Given the following code:
#!/usr/bin/perl
use strict;
sub handler {
my %foo=(a=>1,b=>2,c=>3);
a(\%foo);
print "A -> $foo{a} B -> $foo{b} C -> $foo{c}\n" ;
}
sub a
{
my $ref=shift;
$ref->{a} = 100;
my %copy=%$ref;
$copy{a} = 10;
my $ptr =\$ref->{b};
$$ptr = 20;
}
What is the correct jargon for the 3 separate constructs?
I think of them as references, copies and
another syntax to do a reference that I think of as
pointers.
Another question I have is in regards to performance and memory
use:
Given that %foo starts to be 10 or 20 items, and this
would be running in mod_perl, I sometimes use the
my %foo = %$foo construct to make the syntax easier
to type, but it does make a copy. Perl is famous for
not giving memory back, so i assume that making a
copy in a sub will start to gobble ram if the hash
is of appreciable size. At what point does perl
free ram used for my() constructs in subroutines?
Does it ever?
Does it keep it on the perl stack and reuse it?
Similarly, I have a mod_perl based system thats just crazy for ram use.
With PerlFreshRestart On, the parents and children grow by 30 megs a day. But, strangely enough, they grow only in the shared section. private section ( difference between ram and shared size) is only about 2 megs per process.
It seems that somehow PerlFreshRestart does not re-use the ram allocated for earlier copies of the libraries. I've turned off FreshRestart but it still seems to leak. I SIGUSR1 the process every night for log rotation, and this seems to be when the process memory growth occurs.
Anything I can do?
--
Jay "Yohimbe" Thorne, alpha geek for UserFriendly