Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Proccess Memory Size
Author:Tornado
Category:Win32API
File Size:1020 Bytes
Uploaded at:20-Dec-02 09:26:49 am
Description:
  Calculates the memory size of a specified process.
  
This gets all memory used by a specific process
Assume that dwProcessID is an ID of a process :)

 HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE, dwProcessID);
 DWORD dwSize = 0; // Will contain the total memory usage when we're done!

 MODULEENTRY32 module;
 module.dwSize = sizeof(module);

 if (Module32First(hSnapshot, &module))
 {
  do
  {
   dwSize += module.modBaseSize;
  }while (Module32Next(hSnapshot, &module));
 }

 HEAPLIST32 heap;
 heap.dwSize = sizeof(heap); 

 // Get all memory used by the heap
 if (Heap32ListFirst(hSnapshot, &heap))
 {
  do
  {
   HEAPENTRY32 heapentry;
   heapentry.dwSize = sizeof(heapentry);
   if (Heap32First(&heapentry,heap.th32ProcessID,heap.th32HeapID))
   {
    do
    {
     if (heapentry.dwFlags != LF32_FREE) // If the block is currently used
      dwSize += heapentry.dwBlockSize;
    }while (Heap32Next(&heapentry));
   }
  }while (Heap32ListNext(hSnapshot,&heap));
 }
 CloseHandle(hSnapshot);
User Contributed Comments(None)
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[116858]
2D Rotated Rectangles Collision Detection[88948]
Keyboard Hook[77246]
UDP[65800]
HTTP Proxy[41189]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11557]
PS2 Mouse Driver[6953]
Wave Format Player[5788]
Reading FAT12[5615]
CodeGuru[5355]


All rights reserved to RageStorm © 2009