![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Very simple memory status program in C++ (Windows)
Well you can just open the taks manager (taskmgr.exe / ctrl+alt+del), but this migth be useful in certain circumstances. (Or maybe you can't find it on google as fast.) I basically changed the printf's from MSDN to cout.
![]() // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatusex.asp
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
const int MB = 1048576; // A megabyte is 1,048,576 bytes
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
cout << statex.dwMemoryLoad << " percent of memory is in use." << endl;
cout << endl;
cout << "There are " << statex.ullTotalPhys/MB << " total megabytes of physical memory." << endl;
cout << "There are " << statex.ullAvailPhys/MB << " free megabytes of physical memory." << endl;
cout << endl;
cout << "There are " << statex.ullTotalPageFile/MB << " total megabytes of paging file." << endl;
cout << "There are " << statex.ullAvailPageFile/MB << " free megabytes of paging file." << endl;
cout << endl;
cout << "There are " << statex.ullTotalVirtual/MB << " total megabytes of virtual memory." << endl;
cout << "There are " << statex.ullAvailVirtual/MB << " free megabytes of virtual memory." << endl;
cout << endl;
cout << "There are " << statex.ullAvailExtendedVirtual/MB << " free megabytes of virtual memory." << endl;
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#2 |
|
Professional Programmer
|
What did you compile this in? I tried to compile it in Dev-Cpp, but it had errors. However, MSDN's C version of the program compiled without complaining. Still pretty cool, as I can see what the program is doing by looking at the code.
![]()
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#3 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
![]()
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#4 | |
|
Hobbyist
Join Date: Sep 2005
Posts: 266
Rep Power: 4
![]() |
Quote:
![]() If you took a second to look in 'winbase.h' that ships with Dev-C++ you would see: typedef struct _MEMORYSTATUS {
DWORD dwLength;
DWORD dwMemoryLoad;
DWORD dwTotalPhys;
DWORD dwAvailPhys;
DWORD dwTotalPageFile;
DWORD dwAvailPageFile;
DWORD dwTotalVirtual;
DWORD dwAvailVirtual;
} MEMORYSTATUS,*LPMEMORYSTATUS;
#if (_WIN32_WINNT >= 0x0500)
typedef struct _MEMORYSTATUSEX {
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
#endifSo, the following will fix the problem: #define _WIN32_WINNT 0x0500 Seriously, learn to dig a little. It'll save countless hours of fumbling around. |
|
|
|
|
|
|
#5 |
|
Professional Programmer
|
Yea, I should have looked at the header file.
![]()
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|