I'm building a binary tree, which is using quite a lot of memory, and I'm conserned.

The data file that is being loaded is about 2 megs, though my data structure in perl takes about 100 megs.

I am using arrays instead of hashes every place that I can and perl objects for the nodes and the leaves.

I'm using leaf pushing to limit the data stored in nodes, and my tree is 31 nodes deep (though I'm storing prefixes which can be any number of nodes, most are 24 bits long thus creating 23 nodes and a leaf.)

In this I'm storing about 93,000 prefixes.

Although that sounds like a lot, remember this is a binary tree, so the number of internal nodes is somewhat limited.

Now should perl be using 100 megs? (I'm deleting null leaves and keeping refs rather than actual strings for the values in the leaves. I also do not have any circular refs or such. Also the object data is implemented as an array.) Here is the new function for both the node and the leaf:
# Node: sub new{ my $self = []; $self->[$node::child]=[]; $self->[$node::leaves] = undef; $self->[$node::myDepth] = undef; $self->[$const::getType] = "Node"; # Added/Changed by KIN # trying to limit mem usage # Date: Tuesday, August 06, 2002 @ 10:18 AM if(not($const::LSNmode == 1)){ $self->[$node::nodes] = undef; $self->[$node::bits] = undef; }else{ $self->[$node::lsnBits] = undef; $self->[$node::nodeBits] = undef; $self->[$node::isLSN] = undef; $self->[$node::reBits] = undef; $self->[$node::reNodes] = undef; } bless($self); return $self; } # Leaf: sub new{ my $self = []; $self->[$ptr::weight] = 0; $self->[$ptr::value] = undef; $self->[$const::getType] = "Leaf"; bless($self); return $self; }

Thanks,
Abitkin

In reply to Possible Memory Usage Issues by abitkin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.