Counting memory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • metdos
    New Member
    • Aug 2007
    • 8

    Counting memory

    Is there a way calculating memory usage of program?

    For example, I want to print to screen memory usage of my program in particular time periods.

    Thanks.
  • sanctus
    New Member
    • Mar 2007
    • 84

    #2
    Originally posted by metdos
    Is there a way calculating memory usage of program?

    For example, I want to print to screen memory usage of my program in particular time periods.

    Thanks.
    If you are using linux:
    If you are able to save it I don't know, but if you just want to see how much active memory a program is using, you type "top" (without the ") and then look at RES and %CPU.
    Hope it helps

    On windows I don't know.

    Comment

    • metdos
      New Member
      • Aug 2007
      • 8

      #3
      Originally posted by sanctus
      If you are using linux:
      If you are able to save it I don't know, but if you just want to see how much active memory a program is using, you type "top" (without the ") and then look at RES and %CPU.
      Hope it helps

      On windows I don't know.

      I will produce new objects of class, dynamically(I will add them to a vector) I want to cut off producing new objects when for example 512 MB memory is used.

      Thanks anyway :)

      Comment

      • Matthew Page
        New Member
        • Jul 2007
        • 36

        #4
        Originally posted by metdos
        I will produce new objects of class, dynamically(I will add them to a vector) I want to cut off producing new objects when for example 512 MB memory is used.

        Thanks anyway :)
        You can get the size of the objects and then calculate how many it would take to reach your size limit. Then just stop when you reach that number. Or keep a running total in a variable and quit when you reach your limit. It's probably not exactly what you want to do, though...

        Comment

        • RRick
          Recognized Expert Contributor
          • Feb 2007
          • 463

          #5
          In C++, you can overload the global new and delete operators. The C++ book says this is not for the faint of heart, so beware.

          Try this link: http://www.relisoft.co m/book/tech/9new.html

          My idea is to overload new/delete with others that store/update memory info and then call the original new/delete. I'm not sure how the last step is performed.

          Comment

          Working...