Helpful, indeed.
What I recognized:
- allocating a big chunk of memory at once is evil (for releasing it afterwards):
use strict;
$| = 1;
print "$$\n"; #top -p $$
print "Test, Allocating a large string \n"; <>;
{
my $foo = 'X' x 100000000;
print "Large String allocated.\n";<>;
undef $foo;
print "Large String deallocated.\n";<>;
}
print "2nd Large String.\n";<>;
{
#evil: my $foo2 = 'X' x 100000000;
my $foo2;
$foo2 .= 'x' x 1000 for (1 .. 100000);
print "2nd Large String allocated.\n";<>;
undef $foo2;
print "2nd Large String deallocated.\n";<>;
}
print "Now what? Press enter to exit";
<>;
As you can see the memory used for $foo2 is returned to the OS. So my initial example was not correct.
May I ask you another question, which puzzles me:
The above example also shows that at the end of the of script there are still 97m allocated (due to $foo). Also, the variable $foo2 does not use the previous allocated chunks of $foo (because the usage also rises up to total usage 192m.
Is the caused by the overhead of the internal memory handling of perl?
Thanks,
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.