Click here to Skip to main content
15,915,775 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to get total installed (physical) RAM ? Pin
Luc Pattyn16-Nov-10 12:00
sitebuilderLuc Pattyn16-Nov-10 12:00 
GeneralRe: how to get total installed (physical) RAM ? Pin
Dave Kreskowiak16-Nov-10 13:12
mveDave Kreskowiak16-Nov-10 13:12 
AnswerRe: how to get total installed (physical) RAM ? Pin
Luc Pattyn16-Nov-10 13:20
sitebuilderLuc Pattyn16-Nov-10 13:20 
GeneralRe: how to get total installed (physical) RAM ? Pin
Dave Kreskowiak16-Nov-10 14:50
mveDave Kreskowiak16-Nov-10 14:50 
AnswerRe: how to get total installed (physical) RAM ? Pin
Luc Pattyn16-Nov-10 14:56
sitebuilderLuc Pattyn16-Nov-10 14:56 
GeneralRe: how to get total installed (physical) RAM ? Pin
Dave Kreskowiak16-Nov-10 13:14
mveDave Kreskowiak16-Nov-10 13:14 
GeneralRe: how to get total installed (physical) RAM ? Pin
Jacob D Dixon16-Nov-10 13:52
Jacob D Dixon16-Nov-10 13:52 
AnswerRe: how to get total installed (physical) RAM ? [modified] Pin
Luc Pattyn16-Nov-10 11:56
sitebuilderLuc Pattyn16-Nov-10 11:56 
This is what I use, based on a Win32 function and P/Invoke:

// get physical RAM size (in bytes)
public static long GetPhysicalRAMSize() {
    MEMORYSTATUSEX ms=new MEMORYSTATUSEX();
    ms.Length=64;
    GlobalMemoryStatusEx(ref ms);
    long RAM=ms.TotalPhys;
    RAM=(RAM+0x000FFFFF)&0x7FFFFFFFFFF00000L;   // round up to next 1MB  [EDITED]
    return RAM;
}

[DllImport("kernel32.dll")]
public static extern void GlobalMemoryStatusEx(ref MEMORYSTATUSEX ms);


public struct MEMORYSTATUSEX {
    public int Length;              // DWORD
    public int MemoryLoad;              // DWORD
    public long TotalPhys;              // DWORDLONG
    public long AvailPhys;              // DWORDLONG
    public long TotalPageFile;          // DWORDLONG
    public long AvailPageFile;          // DWORDLONG
    public long TotalVirtual;           // DWORDLONG
    public long AvailVirtual;           // DWORDLONG
    public long AvailExtendedVirtual;       // DWORDLONG
}


(together with some using statements).

It reports 3070MB (out of 3072MB) on a 3GB system (Vista/32) and 3957MB (out of 4096MB) on a 4GB system (Win7/64).

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

modified on Wednesday, November 17, 2010 10:14 AM

GeneralRe: how to get total installed (physical) RAM ? Pin
igalep13217-Nov-10 8:05
igalep13217-Nov-10 8:05 
AnswerRe: how to get total installed (physical) RAM ? Pin
Luc Pattyn16-Nov-10 15:31
sitebuilderLuc Pattyn16-Nov-10 15:31 
GeneralRe: how to get total installed (physical) RAM ? [modified] Pin
igalep13216-Nov-10 22:35
igalep13216-Nov-10 22:35 
GeneralRe: how to get total installed (physical) RAM ? Pin
Dave Kreskowiak17-Nov-10 3:35
mveDave Kreskowiak17-Nov-10 3:35 
AnswerRe: how to get total installed (physical) RAM ? Pin
igalep13217-Nov-10 8:19
igalep13217-Nov-10 8:19 
GeneralRe: how to get total installed (physical) RAM ? Pin
Luc Pattyn17-Nov-10 4:16
sitebuilderLuc Pattyn17-Nov-10 4:16 
Questionhow to get the particular data from the repeater Pin
Dhyanga16-Nov-10 4:43
Dhyanga16-Nov-10 4:43 
AnswerRe: how to get the particular data from the repeater Pin
Manfred Rudolf Bihy16-Nov-10 5:56
professionalManfred Rudolf Bihy16-Nov-10 5:56 
GeneralRe: how to get the particular data from the repeater Pin
Dhyanga16-Nov-10 6:52
Dhyanga16-Nov-10 6:52 
GeneralRe: how to get the particular data from the repeater Pin
Manfred Rudolf Bihy16-Nov-10 10:13
professionalManfred Rudolf Bihy16-Nov-10 10:13 
AnswerRe: how to get the particular data from the repeater Pin
Richard MacCutchan16-Nov-10 6:48
mveRichard MacCutchan16-Nov-10 6:48 
QuestionMessage Removed Pin
16-Nov-10 2:18
SepantaNima16-Nov-10 2:18 
AnswerRe: Error in Updateing Record In SQL2008 Pin
Abhinav S16-Nov-10 2:20
Abhinav S16-Nov-10 2:20 
QuestionError in Updateing Record In SQL2008 Pin
SepantaNima16-Nov-10 2:16
SepantaNima16-Nov-10 2:16 
AnswerRe: Error in Updateing Record In SQL2008 Pin
Abhinav S16-Nov-10 2:17
Abhinav S16-Nov-10 2:17 
GeneralRe: Error in Updateing Record In SQL2008 Pin
SepantaNima16-Nov-10 2:27
SepantaNima16-Nov-10 2:27 
AnswerRe: Error in Updateing Record In SQL2008 Pin
jschell16-Nov-10 8:54
jschell16-Nov-10 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.