Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 30th, 2004, 5:45 AM   #1
extractor
Newbie
 
Join Date: Nov 2004
Posts: 5
Rep Power: 0 extractor is on a distinguished road
Is there a function in c++ to measure memory use of a program?
extractor is offline   Reply With Quote
Old Nov 30th, 2004, 8:39 AM   #2
Dia_Byte
Programmer
 
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0 Dia_Byte is on a distinguished road
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>
Dia_Byte is offline   Reply With Quote
Old Nov 30th, 2004, 10:02 AM   #3
Eggbert
Professional Programmer
 
Eggbert's Avatar
 
Join Date: Nov 2004
Posts: 250
Rep Power: 4 Eggbert is on a distinguished road
>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.
Eggbert is offline   Reply With Quote
Old Dec 2nd, 2004, 10:34 AM   #4
Dia_Byte
Programmer
 
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0 Dia_Byte is on a distinguished road
there is

look what

i will look around my VB codes and when i find something i'll post it here
__________________
<removed by Administrator>
Dia_Byte is offline   Reply With Quote
Old Dec 3rd, 2004, 7:40 AM   #5
Dia_Byte
Programmer
 
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0 Dia_Byte is on a distinguished road
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>
Dia_Byte is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC