Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Memory Tracker Tool

0.00/5 (No votes)
15 Nov 2004 1  
Tracking memory resources

Introduction

This article concentrates on tracking system memory parameters in real time. The system memory parameters will depend on the policy of memory management by the kernel. This includes the type of paging, type of relocation and algorithms behind the aforesaid processes.

About Memory Management

This topic is about the mechanism and the requirements behind system memory management. Often the physical memory available in your system is very low considered to the amount of actual memory needed for running individual processes. This situation becomes critical in a multitasking operating system like Windows. So the available physical memory should be managed in an optimized fashion to avail full system throughput. The actual physical memory thus get extended to a particular limit by the concept of Virtual Memory. This concept is applied by swapping sections of RAM memory in and out of the system hard disk. The swapped sections are called pages which we will be discussing in our next section. Since swapping involves CPU time memory should be optimized to produce minimum chances of swapping. But anyhow, it cannot be avoided too.

Paging

The process which is to be brought to the RAM is not brought as such as a whole. Instead, it is broken into pieces called pages for efficient management of memory and ease of swapping. When it is broken into pieces, the whole process need not be swapped in/out of the disk frequently. Hence each page of process will occupy a corresponding frame of divided memory. For more information regarding the above processes, perhaps you would go to http://www.linux.com/.

About the code

All the above information is displayed graphically in the application uploaded here with. The application would show you how much physical memory your system has and the corresponding payloads. The code runs as follows: [I am including only the code with relevance. Rest being the same as generated by AppWizard]

#define MEMTRACKTIMER 10 // Declaring a timer for constant memory track

The function GlobalMemoryStatus(LPMEMORYSTATUS memStat); defined in winbase.h, will collect all the information about the memory and fill the same in a MEMORYSTATUS structure. The structure runs as below:

typedef struct _MEMORYSTATUS {

DWORD dwLength; // Size of the structure [OPTIONAL]

DWORD dwMemoryLoad; /* Windows NT 4.0 and earlier: The percentage of approximately the last 1000 pages of physical memory that is in use. Windows 2000 and later: The approximate percentage of total physical memory that is in use. */

SIZE_T dwTotalPhys; // Total physical memory

SIZE_T dwAvailPhys; // Total available physical memory

SIZE_T dwTotalPageFile; // Total pages committed to memory

SIZE_T dwAvailPageFile; // Total available memory that can be // committed as pages

SIZE_T dwTotalVirtual; // Total virtual memory

SIZE_T dwAvailVirtual; // Total available virtual memory

}MEMORYSTATUS, *LPMEMORYSTATUS;

The object of above structure when passed into the function would fill the structure accordingly. That's it...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here