Solved

As to know Which size of RAM?

Posted on 2000-03-21
7
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 314
Eclipse IDE - Cannot copy/paste from console output 8 385
How do I get Window Title of all opened process? 4 60
Bitwise and to sum elements 2 52
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

734 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