Windows CPU Memory Network Performance Statistics Article 1 memory

Source: Internet
Author: User

Recently, I used the Windows system performance statistics program to collect statistics on CPU usage, memory usage, and network traffic. Now I want to sort it out (three articles in total) and hope to help you.

The directory is as follows:

1. Windows system CPU Memory Network Performance Statistics Article 1 memory

2. Windows CPU Memory Network Performance Statistics Article 2 CPU

3. Windows CPU Memory Network Performance Statistics Article 3 network traffic

 

This document describes the memory usage of the system, including memory usage, total physical memory size, available physical memory size, total virtual memory size, and available virtual memory size. It is very easy to count the memory usage of the system. simply use the globalmemorystatus function for query. The function prototype is as follows:

Void winapiglobalmemorystatus (

_ Out lpmemorystatus lpbuffer

);

This function will output a struct of the memorystatus type, which describes the memory usage in the system. For details, see the code:

// Windows system CPU memory network performance statistics first article memory globalmemorystatus // By morewindows-(http://blog.csdn.net/MoreWindows) # include <stdio. h> # include <windows. h> const int kb_div = 1024; const int mb_div = 1024*1024; int main () {printf ("Windows CPU Memory Network Performance Statistics Article 1 memory globalmemorystatus \ n "); printf ("-- by morewindows (http://blog.csdn.net/MoreWindows) -- \ n"); memorystatus memstatus; globalmemorystatus (& memstatus); printf ("current memory usage: % d % \ n ", memstatus. dwmemoryload); printf ("total system physical memory: % dkb (% DMB) \ n", memstatus. dwtotalphys/kb_div, memstatus. dwtotalphys/mb_div); printf ("currently available physical memory: % dkb (% DMB) \ n", memstatus. dwavailphys/kb_div, memstatus. dwavailphys/mb_div); printf ("Total System Virtual Memory: % dkb (% DMB) \ n", memstatus. dwtotalvirtual/kb_div, memstatus. dwtotalvirtual/mb_div); printf ("Current idle virtual memory: % dkb (% DMB) \ n", memstatus. dwavailvirtual/kb_div, memstatus. dwavailvirtual/mb_div); printf ("total system page files: % dkb (% DMB) \ n", memstatus. dwtotalpagefile/kb_div, memstatus. dwtotalpagefile/mb_div); printf ("Current idle page file: % dkb (% DMB) \ n", memstatus. dwavailpagefile/kb_div, memstatus. dwavailpagefile/mb_div); Return 0 ;}

The running result on the local machine is as follows: Haha, 2 GB memory is enough for the XP system. Changing to win7 certainly won't have such available memory.

 

 

Because the memorystatus struct is stored in DWORD for memory size, DWORD has only four bytes, and the maximum size is 4 GB. Therefore, when the system memory is larger than 4 GB, some problems will occur. Therefore, Windows provides another function, globalmemorystatusex. The function prototype is as follows:

Boolwinapiglobalmemorystatusex (

_ In_out lpmemorystatusexlpbuffer

);

This function is the enhanced version of the globalmemorystatus function. It will output a struct of the memorystatusex type. This structure uses the dwordlong type variable to describe the memory size. dwordlong is similar to _ int64, which occupies 8 bytes. The following provides the source code for using the globalmemorystatusex function to calculate memory information:

// Windows system CPU memory network performance statistics first article memory globalmemorystatusex // By morewindows-(http://blog.csdn.net/MoreWindows) # include <stdio. h> # include <windows. h> const int kb_div = 1024; const int mb_div = 1024*1024; int main () {printf ("Windows CPU Memory Network Performance Statistics Article 1 memory globalmemorystatusex \ n "); printf ("-- by morewindows (http://blog.csdn.net/MoreWindows) -- \ n"); memorystatusex memstatusex; memstatusex. dwlength = sizeof (memstatusex); If (globalmemorystatusex (& memstatusex) {printf ("current memory usage: % d % \ n", memstatusex. dwmemoryload); printf ("total system physical memory: \ t % i64dkb (% i64dmb) \ n", memstatusex. ulltotalphys/kb_div, memstatusex. ulltotalphys/mb_div); printf ("currently available physical memory: \ t % i64dkb (% i64dmb) \ n", memstatusex. ullavailphys/kb_div, memstatusex. ullavailphys/mb_div); printf ("Total System Virtual Memory: \ t % i64dkb (% i64dmb) \ n", memstatusex. ulltotalvirtual/kb_div, memstatusex. ulltotalvirtual/mb_div); printf ("currently idle virtual memory: \ t % i64dkb (% i64dmb) \ n", memstatusex. ullavailvirtual/kb_div, memstatusex. ullavailvirtual/mb_div); printf ("total system page files: \ t % i64dkb (% i64dmb) \ n", memstatusex. ulltotalpagefile/kb_div, memstatusex. ulltotalpagefile/mb_div); printf ("Current idle page file: \ t % i64dkb (% i64dmb) \ n", memstatusex. ullavailpagefile/kb_div, memstatusex. ullavailpagefile/mb_div);} return 0 ;}

The running result is as follows:

 

 

 

This article introduces and demonstrates the globalmemorystatus and globalmemorystatusex functions to query memory usage. The following two articles: Windows system CPU memory network performance statistics 2 CPU and Windows system CPU memory network performance statistics 3 network traffic will respectively describe the query of CPU usage and network traffic statistics, welcome to continue browsing.

 

 

Reprinted please indicate the source, original address: http://blog.csdn.net/morewindows/article/details/8459219

Welcome to Weibo: http://weibo.com/MoreWindows

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.