On 9/14/07, John W. Krahn <[EMAIL PROTECTED]> wrote:
snip
> > Does perl compiler
> > use this link list concept and keeps it hidden from us?
>
> I haven't read the source code but it probably does somewhere.
snip

I just took a quick look and it appears as if AVs (the implementation
of Perl's arrays) are built on top of C arrays, so it does need
contiguous memory.  So, if you do have heavily fragmented memory and
need to allocate a lot of data you may want to implement a linked list
using hash based nodes:

my $head = { data => 1, next => undef };
$head->{next} = { data => 2, next => undef };
$head->{next}{next} = { data => 3, next => undef };
$head->{next}{next}{next} = { data => 4, next => undef };
$head->{next}{next}{next}{next} = { data => 5, next => undef };

for (my $node = $head; $node; $node = $node->{next}) {
    print "$node->{data}\n";
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to