in reply to perl memory use question

My test says it takes about 200Mb for a single-linked list.

If you don't need linked lists, using plain arrays is probably more memory efficient.

#!perl/bin/perl use strict; $|=1; my ($list1,$list2); print "Making list1\n"; for (0 .. 1_000_000) { my $head = $list1; $list1 = ["a" x 40,\$head]; } print "Making list2\n"; for (0 .. 60_000) { my $head = $list2; $list2 = ["b" x 338,\$head]; } print "Press enter to exit: "; my $dummy = <STDIN>;
update: perl should be fine with that kind of usage. just remember that perl is no where near as memory-efficient as C can be. perl values have a significant overhead. especially if you have many small objects.

update 2: i get a segfault from this script at destruction. that's not right. (tested perl 5.00504 & perl 5.8.8)

update 3: ok, increasing the stack size limit (ulimit -s 400000) fixes the problem.

Replies are listed 'Best First'.
Re^2: perl memory use question
by liverpole (Monsignor) on Jun 03, 2007 at 20:53 UTC
    Joost,

    For fun, I tried running your program on ASP (version 5.8.8, Binary build 819), and got a software exception.  That's not to say it's anything with your program of course, I'm sure it's just my memory configuration.

    I narrowed it down to:

    #!perl/bin/perl use strict; use warnings; $|=1; my ($list1); print "Making list1\n"; for (0 .. 93132) { my $head = $list1; $list1 = ["a" x 40,\$head]; }

    which does give the error.  When 93132 is changed to 93131, the error does NOT occur.

    This is with Windows XP, and 512 MB of RAM.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re^2: perl memory use question
by exodist (Monk) on Jun 03, 2007 at 22:08 UTC
    how do I use ulimit/ set the stack size? is it a flag when I run the script, or is it a line in the script?