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 04: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[106834]
2D Rotated Rectangles Collision Detection[79973]
Keyboard Hook[69115]
UDP[53088]
HTTP Proxy[36327]

::Top 5 Samples::
2D ColDet Rotated Rectangles[10643]
PS2 Mouse Driver[6125]
Wave Format Player[5010]
Reading FAT12[4896]
CodeGuru[4595]


All rights reserved to RageStorm © 2009