[ACCEPTED]-How can I get the total physical memory in C#?-memory-management
Accepted answer
I find my mistake from: http://www.pinvoke.net/default.aspx/kernel32/GlobalMemoryStatusEx.html
I Changed
internal static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
To
static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);
and 1 changed
GlobalMemoryStatusEx(ref statEX);
To
GlobalMemoryStatusEx(statEX);
It work correctly. Tanks
How about:
My.Computer.Info.TotalPhysicalMemory
My.Computer.Info.AvailablePhysicalMemory
0
If c# you can:
Reference the Microsoft.VisualBasic
assembly.
Then 2 import Microsoft.VisualBasic.Devices
namespace.
And finally use ComputerInfo 1 to get the total physical memory.
int bytesPerMebibyte = (1 << 20); // http://physics.nist.gov/cuu/Units/binary.html
ComputerInfo myCompInfo = new ComputerInfo();
string physicalMemory = "Physical Memory: "
+ (myCompInfo.TotalPhysicalMemory / bytesPerMebibyte) + " MB";
you can use this templates:
long memory = Process.GetCurrentProcess().PeakVirtualMemorySize64;
And another properties 1 with names Peak*64
You forgot to set statEX.dwLength
before calling GlobalMemoryStatusEx
.
MEMORYSTATUSEX statEX = new MEMORYSTATUSEX();
statEX.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
GlobalMemoryStatusEx(ref statEX);
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.