Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^6: Perl memory usage

by kscaldef (Pilgrim)
on Sep 02, 2005 at 08:26 UTC ( [id://488574]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Perl memory usage
in thread Performance, Abstraction and HOP

Is 6x really that crazy? Doesn't a typical generic C tree use about 4x? (If you're storing integers in the tree. If you are storing something larger, the overhead is smaller.) The perl array includes at least a reference count and a length that aren't in the C Node struct, so 6x quickly becomes plausible.

Replies are listed 'Best First'.
Re^7: Perl memory usage
by Anonymous Monk on Sep 02, 2005 at 14:56 UTC
    Well, on a 32bit machine, it is 3x larger...
    struct tree { int elem; struct tree *left, *right; }; int main(int argc, char **argv) { printf("sizeof(int)=%d,sizeof(struct tree)=%d\n", sizeof(int),sizeof(struct tree)); }
    ...of course, the 12 bytes from above is a tad bit slimmer than the apparently 112 byte structure on the perl side.

      I said "generic" tree, along the lines of a glib GTree. So, there's an extra pointer to the data:

      struct Node { gpointer data; struct Node *left; struct Node *right; }

      So, 3 (probably 4 byte) pointers, plus the data pointed to.

      The perl implementation, though, is not a simple struct. Instead, the three members are SVs in an array, and an SV is significantly larger than a single pointer. Then there's some additional overhead for book-keeping on the array.

        If anyone out there is in the know, I'd still be interested how you get from the ~76 byte guesstimate, to the 112 byte answer. There must be some low-level document somewhere where it is explained (or maybe a pointer to a chunk of code). I'm still looking at PerlGuts Illustrated. And I think we can all agree that a less bloated way to represent trees in Perl6 would be nice. Right?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://488574]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found