in reply to Traditional Linked List and Perl's built-in Data Structure

Basically, almost any tree structure or graph, will use less memory and have faster traversal times, if implemented in C using direct pointer access and manipulations, than when the same structures are built using Perl's references.

As fast as Perl's hashes and arrays are, you do pay some costs for their generality and ease of use. Indirecting through a reference costs more than indirecting through a raw address, and raw C-style arrays use considerably less memory than the equivalent Perl arrays.

However, for those costs, you get a whole slew of benefits:

For anything other than the most demanding of applications that need extremely fast response times, or to manipulate huge amounts of memory, the gains far outweight the costs. And even when you do need to manipulate large volumes of data, a little extra effort can sometimes allow you to accomodate upto an order of magnitude more data in the same amount of ram, whilst still avoiding the need to leave the convenience of Perl and get down and dirty with C.

That said, a well thought out set of tree primitives written in XS, available in Perl would be a nice addition.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Edited by planetscape - added <ul></ul> tags

  • Comment on Re: Traditional Linked List and Perl's built-in Data Structure

Replies are listed 'Best First'.
Re^2: Traditional Linked List and Perl's built-in Data Structure
by ph713 (Pilgrim) on Dec 17, 2005 at 16:08 UTC
    That said, a well thought out set of tree primitives written in XS, available in Perl would be a nice addition.
    Has there been any consideration of adding some new intrinsic data structure types to perl6, like linked lists, or binary / n-ary / red-black / balanced / whatever trees, etc?

      I don't know. That might make a good question for the P6 mailling list.

      If method call overheads are substantially lower, and if the early proposal that it would be possible to specify (or advise) the storage size for array elements, (something like my @array :integer; from memory), then it may be unnecessary, as it may be possible to create a P6 class or mixin for trees, graphs, etc. that would be fast and efficient. I guess it will depend upon how successful Parrot is in keeping the levels of indirection down.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.