How to get the memory usage using C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fantasticamir
    New Member
    • Apr 2007
    • 42

    How to get the memory usage using C++

    Guys,

    I have a program that has some stages. I am looking for a function/method or anything that tell me how much each part of the code (or even specific class) consumes memory.

    Please help me out with any type of method by which I can measure the used memory of my code or...

    I know top and ps ... I need a some functions, since I need to insert it into my program.

    Thanks,

    Amir.
  • arnaudk
    Contributor
    • Sep 2007
    • 425

    #2
    Use one of the many memory profilers/debuggers out there, like valgrind, for example. top and ps monitor the resource utilisation of an entire process and can not peer into the different parts of your program.

    Comment

    • fantasticamir
      New Member
      • Apr 2007
      • 42

      #3
      well I can't, i am running my program on a server that I have no access to...:-( any more help?

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #4
        There isn't a way, sorry. Although you can manually eyeball a section of code, and assuming the platform you are working with, make a good guess on how much memory will be needed. Depends.

        Why don't you give us some context? What do you really want?

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Originally posted by fantasticamir
          well I can't, i am running my program on a server that I have no access to...:-( any more help?
          Well run a test of it on your local machine and run a profiler on it there.

          Run the task manager or download SysMon and run that on your server if it's windows they report program memory usage. (I would assume that Linux has a similar program but wouldn't know what it is.)

          Don't be so closed minded it sounds like you will need to be creative to get the statistics you want.

          Comment

          Working...