To answer a few questions asked by /msg.

  1. What is Perl>?

    It's a twenty-line script called p1.pl that is effectively similar to doing perl -de1 except is loads a few useful modules and accepts multiple lines of input until one is terminated with ;;

  2. What is the meaning of the double semi-colons?

    See above.

  3. Why the diff is so big between the two examples: total_size( \@a );; and total_size( \%:: );;

    %\:: is (effectively) the symbol table for whole script, including all modules loaded.

    When you do total_size( \%:: );;, it is accumulating the sizes of most* the code space, and all of the data space use by everything that makes up the script, inclduing that space used by all modules that are loaded, and some of the code and data space loaded (into every script) by Perl itself.

    *See the Devel::Size docs where it explains that the numbers for CVs (code structures) are not complete. Don't expect the accumulated sizes to add up exactly. It gives a good idea of where your script is consuming memory, without being exact.

    It will include the space consumed by any variables created by your program (@a in the example) and various other bits and peices including some of the code and data loaded by the Devel::Size module itself, and the various modules ( Carp, Exporter, XSLoader etc. ) that D::S causes to be loaded.

    The long list in the Update above, is the results of dumping the keys and total_sizes of %:: individually from within p1.pl, and shows amongst other things that it also loads Data::Dumper, and Benchmark.

    It also shows various global structures set up by Perl. Eg.

    • %ENV is using 5,557 bytes.
    • %SIG is using 3,705 bytes.
    • %INC is using 2,495 bytes.
    • @ARGV is using 405 bytes.
    • With a little thought it is possible to work out most of the others.For example, the character '↨' using 407 bytes is ascii 23:
      perl> print ord '↨';; 23

      which translates to $^W, and '↑' is 24, $^X which is the name of the script.

    • ...and so on.

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".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re^2: Total Memory Size Used up by a Perl Script by BrowserUk
in thread Total Memory Size Used up by a Perl Script by monkfan

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.