Solved

As to know Which size of RAM?

Posted on 2000-03-21
7
259 Views
Last Modified: 2010-04-10
As to know Which size of RAM?(C++, AND same in assembler without using interruption)

0
Comment
Question by:alexBrasil
  • 4
  • 2
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2641262
Standard C++ does not provide features for this.

Some operatig systems may provide features for doing so, so you may be able to use OS-specific code do do this.  What OS are you using?
0
 

Author Comment

by:alexBrasil
ID: 2641299
I am using Win95.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2641340
Windows is a virtual memory OS.  The amount of RAM available isn't really all that relevant.  Why do you want it?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 22

Expert Comment

by:nietod
ID: 2641348
In NT you can use GetProcessWorkingSetSize(), which may be more useful to you.  
0
 

Author Comment

by:alexBrasil
ID: 2641476
Win95 shows in the system patterns the size of the RAM, and in boot(bios). also the command " mem " of the dos.

 
0
 
LVL 22

Expert Comment

by:nietod
ID: 2641610
True.  I'm not denying that, I'm just point out that that information is not of much importance to a program runing in windows.  So if you think your program really needs this information, you are probably wrong.  (I also don't know how to get the information, there are not procedures I know of that return it, you can probably find it somewhere in the registry.)  
0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 2641677
Use the GlobalMemoryStatus function.

The program following shows a simple use of the GlobalMemoryStatus function.

//  Sample output:
//  c:\>global
//  The MemoryStatus structure is 32 bytes long.
//  It should be 32.
//  78 percent of memory is in use.
//  There are   65076 total Kbytes of physical memory.
//  There are   13756 free Kbytes of physical memory.
//  There are  150960 total Kbytes of paging file.
//  There are   87816 free Kbytes of paging file.
//  There are  1fff80 total Kbytes of virtual memory.
//  There are  1fe770 free Kbytes of virtual memory.

#include <windows.h>

// Use to change the divisor from Kb to Mb.

#define DIV 1024
// #define DIV 1

char *divisor = "K";
// char *divisor = "";

// Handle the width of the field in which to print numbers this way to
// make changes easier. The asterisk in the print format specifier
// "%*ld" takes an int from the argument list, and uses it to pad and
// right-justify the number being formatted.
#define WIDTH 7

void main(int argc, char *argv[])
{
  MEMORYSTATUS stat;

  GlobalMemoryStatus (&stat);

  printf ("The MemoryStatus structure is %ld bytes long.\n",
          stat.dwLength);
  printf ("It should be %d.\n", sizeof (stat));
  printf ("%ld percent of memory is in use.\n",
          stat.dwMemoryLoad);
  printf ("There are %*ld total %sbytes of physical memory.\n",
          WIDTH, stat.dwTotalPhys/DIV, divisor);
  printf ("There are %*ld free %sbytes of physical memory.\n",
          WIDTH, stat.dwAvailPhys/DIV, divisor);
  printf ("There are %*ld total %sbytes of paging file.\n",
          WIDTH, stat.dwTotalPageFile/DIV, divisor);
  printf ("There are %*ld free %sbytes of paging file.\n",
          WIDTH, stat.dwAvailPageFile/DIV, divisor);
  printf ("There are %*lx total %sbytes of virtual memory.\n",
          WIDTH, stat.dwTotalVirtual/DIV, divisor);
  printf ("There are %*lx free %sbytes of virtual memory.\n",
          WIDTH, stat.dwAvailVirtual/DIV, divisor);
}
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now