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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.