Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

First, note that there are at least two important measures of memory use: total memory size and working set size. I tend to oversimplify them slightly and think of them as "paging file use" and "RAM use", respectively. Total memory size is how many pages of virtual memory your program has been allocated. Working set size is how many pages of memory your program needs to have in RAM at once in order to run smoothly.

If your program uses more total memory than is available to it (either due to quota restrictions or just how much is available to the operating system minus how much the kernel and other processes are using), it will probably die [well, usually malloc() will fail, which will usually either cause a quick death or trigger bugs which cause a slightly slower but more colorful death; but some operating systems will let malloc() succeed but when you actually try to use the memory the OS will notice the problem and kill you (or some other process!)].

If your program needs a larger working set than is available, then it will start "paging" too much and slow down noticeably. The size of the working set has a lot to with how the memory is accessed. By making your data structures such that related items are close together in memory, you can often dramatically reduce your program's working set size. BTW, Perl plays this same trick by trying to arrange for its most-used C subroutines to be close together in memory (which is why we have the pp_hot.c file).

To get the working set size, you'll have to ask the operating system. To get the total memory size, I'd build a version of Perl with DEBUGGING_MSTATS defined and then use Devel::Peek::mstats (though the documentation for this has been moved or purged so you may have to dig for it or reverse engineer it).

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Determining the Memory Usage of a Perl program from within Perl by tye
in thread Determining the Memory Usage of a Perl program from within Perl by princepawn

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (3)
    As of 2018-06-23 12:32 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.