The interpreter mentioned in
Lisp-In-Perl implements them
as two arrays. One for all the 'car|down' nodes, and one for all the 'cdr|right' nodes. But then the nodes don't free themselves when they are no longer being referenced. A garbage collector has to periodically compact the arrays.
Update: I did a rough benchmark of memory used by the two methods, and using array refs used ~3-4 times more memory. Is this because perl over-allocates whenever it allocates an array? Since you can pre-extend an array you know will be large, would it help if it were possible to pre-de-extend an array you know will be small? Here's the code I used (for comments on the fairness of the comparisons):
my @arr;
my @arr1;
my @arr2;
my $i=0;
for (1..1_000_000) {
# This
#push @arr, [undef, undef];
# Or this
push @arr, [++$i, ++$i];
# Vs. this:
#push @arr1, undef;
#push @arr2, undef;
# Or this:
#push @arr1, ++$i;
#push @arr2, ++$i;
}
print "Done\n";
# Then just do a 'ps -lu runrig' at another command prompt when I get
+here
my $str=<STDIN>;
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.