![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 5
Rep Power: 0
![]() |
Is there a function in c++ to measure memory use of a program?
|
|
|
|
|
|
#2 |
|
Programmer
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0
![]() |
a C++ function ... mmmmmm...
i don't know but i'm sure that you can use some API's and types to get the memory i don't remember how i found a VB program a while ago which uses APIs to get the memory try checking MSDN maybe you'lle find anything usefull
__________________
<removed by Administrator> |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 4
![]() |
>Is there a function in c++ to measure memory use of a program?
Not a standard function. You would need to check your system's documentation to see if the system API supports such a thing. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0
![]() |
there is
look what i will look around my VB codes and when i find something i'll post it here
__________________
<removed by Administrator> |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0
![]() |
this is the source code in visual basic :
Option Explicit Private Type MEMORYSTATUS ' the type to get memory status dwLength As Long dwMemoryLoad As Long dwTotalPhys As Long dwAvailPhys As Long dwTotalPageFile As Long dwAvailPageFile As Long dwTotalVirtual As Long dwAvailVirtual As Long End Type Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS) 'the API for memory Const fmt As String = "###,###,###,###" Const skb As String = " Kbyte" Const nkb As Long = 1024 Private Sub Form_Load() Dim MS As MEMORYSTATUS 'declare MS as new type of MEMORYSTATUS MS.dwLength = Len(MS) GlobalMemoryStatus MS ' use the API lbMemStat(0) = Format$(MS.dwMemoryLoad, fmt) & " % used" 'get used memory lbMemStat(1) = Format$(MS.dwTotalPhys / nkb, fmt) & skb 'get total physical memory lbMemStat(2) = Format$(MS.dwAvailPhys / nkb, fmt) & skb 'get available physical Memory lbMemStat(3) = Format$(MS.dwTotalPageFile / nkb, fmt) & skb lbMemStat(4) = Format$(MS.dwAvailPageFile / nkb, fmt) & skb lbMemStat(5) = Format$(MS.dwTotalVirtual / nkb, fmt) & skb 'get total virtual memory lbMemStat(6) = Format$(MS.dwAvailVirtual / nkb, fmt) & skb 'get avialable virual memory End Sub and this is the program in C++ as you ordered written by me : #include <iostream.h> // for the 'cout' function
#include <stdlib.h> // for the 'system' function
#include <windows.h> // for Windows APIs [don't remove !!]
#include <winuser.h> // for Windows APIs too [don't remove !!]
void decs();
int main()
{
_MEMORYSTATUS MS; // declare memory structure MEMORYSTATUS stored in winbase.h
decs();
cout << endl << "Start Of Memory Test ..." << endl << endl;
cout << "Current Memory Utilization : " << MS.dwMemoryLoad << endl;
cout << "Total Memory : " << MS.dwTotalPhys << " Bytes" << endl;
cout << "Available Physical Memory : " << MS.dwAvailPhys << " Bytes" << endl;
cout << "Total Page File : " << MS.dwTotalPageFile << endl;
cout << "Available Page File : " << MS.dwAvailPageFile << " Bytes" << endl;
cout << "Total Virtual Memory : " << MS.dwTotalVirtual << " Bytes" << endl;
cout << "Avialable Virtual Memory : " << MS.dwAvailVirtual << " Bytes" << endl << endl;
cout << "End of memory test ..." << endl << endl;
system("pause"); // the console command 'pause'
return 0;
}
void decs()
{
cout << "************************************" << endl;
cout << "Memory Status Program" << endl;
cout << "By Dia_Byte" << endl;
cout << "************************************" << endl;
}you can compile the source code with DEV_CPP
__________________
<removed by Administrator> |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|