C++ Total RAM

cyberphant0m

Member
Oct 21, 2003
99
0
0
Im writing a function that gets the total amount of memory on the computer in MBs... Here's the code I have...

On line 9 and 12 I get the following errors:

9 - request for member `dwLength' in `MemStruct', which is of non-aggregat type `_MEMORYSTATUS*'
12 - request for member `dwTotalPhysin `MemStruct', which is of non-aggregat type `_MEMORYSTATUS*'
 

Titan

Golden Member
Oct 15, 1999
1,819
0
0
Hm, that looks like win32 code, I must admidt I don't recognize those function calls. The MSDN is no help?

I'm only replying because I wonder what you would get. I was told that from a software perspective, you have "infinite memory," while this is physically not the case, the only way a program could know is by making a syscall to the underlying OS. But what would windows report, physical, or total virtual memory as well?

If you need to find physical, one way is to guesstimate like how sisoft sandra does a cache benchmark. Once access times drop off into the hard drive range, you know you have left physical memory and are paging the hard disk.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Well think about it: a pointer doesn't have members. It appears that you need to do MemStruct->foo, not MemStruct.foo.
 

Ulukai

Member
Nov 29, 2003
28
0
0
Originally posted by: BingBongWongFooey
Well think about it: a pointer doesn't have members. It appears that you need to do MemStruct->foo, not MemStruct.foo.

Even then, it's not pointing to anything.

Best thing to do is change LPMEMORYSTATUS to MEMORYSTATUS and just pass the address of that into GlobalMemoryStatus()

Edit: Oh and dwLength is changed by GlobalMemoryStatus() anyway so line 9 is completely redundant
 

cyberphant0m

Member
Oct 21, 2003
99
0
0
dunno... I was reading the Win32 API documentation, and it said that the calling process should set that member before calling GlobalMemoryStatus()... I guess it doesn't hurt to leave it like that...