Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to find total memory a process is using?

How to find total memory a process is using?

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancehelptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sysop HAL9K com
    wrote on last edited by
    #1

    We use a combination of malloc() and the new operator in our VC++ programs. How can we get a summary of either or both items total memory allocation? The heap walker stuff doesn't seem to do anything unless you use those dinosaur LocalAlloc() / GlobalAlloc() calls which are not portable to Unix. thanks for any help :confused:

    T D 2 Replies Last reply
    0
    • S sysop HAL9K com

      We use a combination of malloc() and the new operator in our VC++ programs. How can we get a summary of either or both items total memory allocation? The heap walker stuff doesn't seem to do anything unless you use those dinosaur LocalAlloc() / GlobalAlloc() calls which are not portable to Unix. thanks for any help :confused:

      T Offline
      T Offline
      Toby Opferman
      wrote on last edited by
      #2

      Are you looking for something that is portable to unix? Here is one way (not portable), the undocumented now documented method. http://www.microsoft.com/msj/0197/hood/hood0197.aspx[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/ntqueryinformationprocess.asp[^] You want to use the ProcessVmCounters. 8bc7c0ec02c0e404c0cc0680f7018827ebee

      T 1 Reply Last reply
      0
      • T Toby Opferman

        Are you looking for something that is portable to unix? Here is one way (not portable), the undocumented now documented method. http://www.microsoft.com/msj/0197/hood/hood0197.aspx[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/ntqueryinformationprocess.asp[^] You want to use the ProcessVmCounters. 8bc7c0ec02c0e404c0cc0680f7018827ebee

        T Offline
        T Offline
        Toby Opferman
        wrote on last edited by
        #3

        Another method would be to use "Performance Counters" on that process. I believe there may be a few other APIs that get various information as well. 8bc7c0ec02c0e404c0cc0680f7018827ebee

        S 1 Reply Last reply
        0
        • T Toby Opferman

          Another method would be to use "Performance Counters" on that process. I believe there may be a few other APIs that get various information as well. 8bc7c0ec02c0e404c0cc0680f7018827ebee

          S Offline
          S Offline
          sysop HAL9K com
          wrote on last edited by
          #4

          Thanks Toby! There's still too much instrumentation for our simple needs. Here is what made the boss happy: C:\Temp>printmemorystats.exe total used 5054, free 760 OK - end of heap total used 10174, free 3816 OK - end of heap total used 12222, free 1760 OK - end of heap total used 16318, free 5848 OK - end of heap total used 24510, free 9936 OK - end of heap total used 40894, free 14024 OK - end of heap total used 73662, free 22128 OK - end of heap total used 139198, free 26216 OK - end of heap total used 270270, free 30304 OK - end of heap total used 532414, free 34392 OK - end of heap #include #include static void PrintMemoryStats(); int main() { int sizemem=1024; int ii; char *foo; for (ii=0; ii<10; ii++) { PrintMemoryStats(); foo = malloc(sizemem); sizemem *= 2; } } static void PrintMemoryStats() { _HEAPINFO hinfo; int heapstatus; long totalUsed = 0, totalFree = 0; hinfo._pentry = NULL; while( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK ) { if (hinfo._useflag == _USEDENTRY) totalUsed += hinfo._size; else if (hinfo._useflag == _FREEENTRY) totalFree += hinfo._size; } printf ("total used %ld, free %ld\n", totalUsed, totalFree); switch( heapstatus ) { case _HEAPEMPTY: printf( "OK - empty heap\n" ); break; case _HEAPEND: printf( "OK - end of heap\n" ); break; case _HEAPBADPTR: printf( "ERROR - bad pointer to heap\n" ); break; case _HEAPBADBEGIN: printf( "ERROR - bad start of heap\n" ); break; case _HEAPBADNODE: printf( "ERROR - bad node in heap\n" ); break; } } -- modified at 15:25 Friday 27th January, 2006

          1 Reply Last reply
          0
          • S sysop HAL9K com

            We use a combination of malloc() and the new operator in our VC++ programs. How can we get a summary of either or both items total memory allocation? The heap walker stuff doesn't seem to do anything unless you use those dinosaur LocalAlloc() / GlobalAlloc() calls which are not portable to Unix. thanks for any help :confused:

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            See if this helps.


            "The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups