Click here to Skip to main content
15,884,237 members
Articles / Desktop Programming / MFC
Article

Memory Tracker Tool

Rate me:
Please Sign up or sign in to vote.
1.16/5 (20 votes)
15 Nov 20042 min read 39K   996   12   3
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 { </P>
<P>DWORD dwLength; // Size of the structure [OPTIONAL]</P>
<P>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. */</P>
<P>SIZE_T dwTotalPhys; // Total physical memory</P>
<P>SIZE_T dwAvailPhys; // Total available physical memory</P>
<P>SIZE_T dwTotalPageFile; // Total pages committed to memory</P>
<P>SIZE_T dwAvailPageFile; // Total available memory that can be // committed as pages</P>
<P>SIZE_T dwTotalVirtual; // Total virtual memory</P>
<P>SIZE_T dwAvailVirtual; // Total available virtual memory</P>
<P>}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


Written By
Technical Lead
India India
I am a personality from Trivandrum , a green peaceful place in Kerala, South India.
I have been an enthusiast of Windows programming when I started creating simple windows when I learnt VC++ in LCC in Trivandrum. From then on its all about Windows in my flesh and blood.
My career graph moves like this:
1. I started working as a C/C++ programmer in a company in Trivandrum where I learnt the ABCs of Software Industry. I worked with them for about 1 year. I could not contine since I was in contract for 1 year.
2. Then I joined another organization in Trivandrum who gave me challenges to love. They made me mad about VC++ and Windows.
I was mad about Embedded Systems which made me, Myself = Embedded Systems + VC++.
3. Software Engineer in a telecom company in Hyderabad, Andhra Pradesh, S.India.
4. Currently working with a telecom company in Bangalore.
I totally, so, have experience of about 4.5 years.

Comments and Discussions

 
Generallittle mistake Pin
Daniel Schade19-Jun-07 2:46
Daniel Schade19-Jun-07 2:46 
QuestionWTF? Pin
Prakash Nadar16-Nov-04 6:09
Prakash Nadar16-Nov-04 6:09 
AnswerRe: WTF? Pin
Sreekanth Muralidharan16-Nov-04 16:17
Sreekanth Muralidharan16-Nov-04 16:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.