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:
- Automated memory management. (No alloc/free to contend with).
- Automated expansion/contraction. (No realloc/memcpy et al).
- Autovivication. (No need to predeclare the size of your arrays).
- Tranparent manipulation, coersion and mixing of strings, integers and reals.
- Automated pointer management. It's (almost) impossible to segfault Perl unlike C.
- Programmer productivity.
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
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.