How to retrieve total amount of system RAM?
Wyverex
wyverex.cypher at gmail.com
Wed Aug 13 13:11:14 PDT 2008
Benji Smith wrote:
> Steven Schveighoffer wrote:
>> Getting system memory isn't part of any standard that I know of (at
>> least on the posix side), and there's not a large demand for it. The
>> API for getting memory is decided on by OS implementors. What you
>> would end up with is a list of versions for not only different OSes,
>> but different versions of the OS. It's along the same lines as
>> getting/setting network interface addresses.
>>
>> From experience (I have written a program to get system memory size),
>> it is not trivial. And not always accurate.
>>
>> This is not to say that it couldn't be added. If you come up with
>> something that looks reasonable, Tango might accept it.
>>
>> -Steve
>
>
> In win32, it looks like the GlobalMemoryStatus (for all non-NT versions)
> and GlobalMemoryStatusEx (for all NT-based versions), from kernel32.dll,
> would do the trick.
>
> http://msdn.microsoft.com/en-us/library/aa366586.aspx
> http://msdn.microsoft.com/en-us/library/aa366589(VS.85).aspx
>
> In linux, a bare-minimum solution would be to read from /proc/meminfo,
> even if there's no POSIX function.
>
> Of course, I'm talking out of my ass here, because my experience with
> C/C++ programming is very thin. I don't know, for example, how you'd
> check for the existence of the GlobalMemoryStatusEx function and fall
> back to GlobalMemoryStatus when it doesn't exist.
>
> It seems doable, though my own systems programming experience is
> probably too lacking for me to make it happen myself.
>
> --benji
Id default to NT version since its Win 2000+,
Then force version flag for non-NT, or dont support 95, 98, ME
version(WIN_NO_NT)
alias GlobalMemoryStatus GlobalMemoryStat;
else
alias GlobalMemoryStatusEx GlobalMemoryStat;
More information about the Digitalmars-d-learn
mailing list