Wednesday, 26 August 2015

PR( 06) C/C++ Program to identify the available memory in the system.




in CPP

#include<windows.h>
#include<iostream.h>
int main()
{
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
cout<<"\nTotal Phisical Memory(MB):-"<<ms.dwTotalPhys/1024/1024;
cout<<"\nTotal Available Phisical Memory(MB):-"<<ms.dwAvailPhys/1024/1024;
cout<<"\nTotal Virtual Memory(MB):-"<<ms.dwTotalVirtual/1024/1024;
cout<<"\nTotal Available Virtual Memory(MB):-"<<ms.dwAvailVirtual/1024;
cout<<"\n";
return 0;
}


**********************************************************************************************


in C


#include <stdio.h>
#include <sys/sysinfo.h>

int main(void)
{
  struct sysinfo myinfo;
  unsigned long total_bytes;

  sysinfo(&myinfo);

  total_bytes = myinfo.mem_unit * myinfo.totalram;


  printf("total usable main memory is %lu B, %lu MB\n",
         total_bytes, total_bytes/1024/1024);

  return 0;

}  
 

No comments:

Post a Comment