Thread: Memory
View Single Post
Old Dec 3rd, 2004, 8: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