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. Get exact memory usage of a process.

Get exact memory usage of a process.

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
2 Posts 2 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.
  • Z Offline
    Z Offline
    zecodela
    wrote on last edited by
    #1

    Hi All, I am debugging my application by printing the Working Set at the specific point with the function provided in psapi.h My purpose is to check which part of my application used up the memory. However, just look at the Working Set is not very conclusive. I found if allocated 1k memory in the app but the Working Set may not grow up 1k accordingly. It will grow eventually(say allocated 10 times 1k, Working Set will grow up around 10k.) In the psapi.h, there are several values such PageFault, PagedPool, Pagefile... i can see those values will change each time when allocating memory. I guess the result of memory allocation action has reflected in those values. What i want to ask is any formula to calculate the exact memory usage of the application? say, i do "new char[128]" the memory usage result will grow up 128byte immediately. Any reply will be appreciated! Thanks! Jim

    B 1 Reply Last reply
    0
    • Z zecodela

      Hi All, I am debugging my application by printing the Working Set at the specific point with the function provided in psapi.h My purpose is to check which part of my application used up the memory. However, just look at the Working Set is not very conclusive. I found if allocated 1k memory in the app but the Working Set may not grow up 1k accordingly. It will grow eventually(say allocated 10 times 1k, Working Set will grow up around 10k.) In the psapi.h, there are several values such PageFault, PagedPool, Pagefile... i can see those values will change each time when allocating memory. I guess the result of memory allocation action has reflected in those values. What i want to ask is any formula to calculate the exact memory usage of the application? say, i do "new char[128]" the memory usage result will grow up 128byte immediately. Any reply will be appreciated! Thanks! Jim

      B Offline
      B Offline
      Bogdan Apostol
      wrote on last edited by
      #2

      When you allocate 128 bytes through "new char[128]", you may not commit any new page of memory!!! My point is that memory allocation is done by the heap manager used by your module. For example, if CRT is the heap manager (msvcrt.dll) you're linking with, all "malloc / new" kind of instructions will be handled by that library, which may reuse previously released memory, or return an address of already commited memory. The heap manager keeps track of your allocations, and commits pages of memory only when needed. For example, on first allocation, a number of pages are commited to support the request. On those pages there's still room for more allocations. Thus, next allocation, if small enough, will not commit more pages, but use the existing commited pages. There're plenty of online resources explaining how a "heap manager" implementation works: http://blogs.technet.com/askperf/archive/2007/06/26/what-a-heap-of-part-one.aspx[^] http://en.wikipedia.org/wiki/Chunking_(computing)[^] http://www.blackhat.com/presentations/bh-usa-06/BH-US-06-Marinescu.pdf[^] http://www.freshpatents.com/Methods-systems-and-computer-program-products-for-managing-a-memory-by-storing-external-objects-in-a-dynamic-heap-dt20051215ptan20050278496.php[^] Best regards,

      Bornish ESRI Developer Network Compilers demystified - Function pointers in Visual Basic 6.0 En

      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