C#怎么获得内存物理内存?
只想获得物理内存大小,不想知道其他的东西。(随便问怎么读取注册表?)
------解决方案--------------------using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
//加入这个命名空间,用于调用系统的DLL
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public struct MEMORYSTATUS1 //这个结构用于获得系统信息
{
internal uint dwLength;
internal uint dwMemoryLoad;
internal uint dwTotalPhys;
internal uint dwAvailPhys;
internal uint dwTotalPageFile;
internal uint dwAvailPageFile;
internal uint dwTotalVirtual;
internal uint dwAvailVirtual;
}
[DllImport("kernel32.dll ")]//调用系统DLL
public static extern void GlobalMemoryStatus(ref MEMORYSTATUS1 lpBuffer); //获得系统DLL里的函数
public Form1()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)//这个是触发事件的按纽
{
MEMORYSTATUS1 vBuffer = new MEMORYSTATUS1();//实例化结构
GlobalMemoryStatus(ref vBuffer);//给此结构赋值