C#获取模拟器存储空间的大小

这个C#程序展示了如何获取模拟器的存储空间信息,包括内存负载、总物理内存、可用物理内存、总页面文件、可用页面文件、总虚拟内存和可用虚拟内存等详细数据。通过调用`GlobalMemoryStatus`和`GetSystemMemoryDivision`两个方法,实现了从模拟器中获取内存状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    public partial class Form1 : Form
    {
        public struct MEMORYSTATUS
        {
            public UInt32 dwLength;       
            public UInt32 dwMemoryLoad;   
            public UInt32 dwTotalPhys;    
            public UInt32 dwAvailPhys;    
            public UInt32 dwTotalPageFile;
            public UInt32 dwAvailPageFile; 
            public UInt32 dwTotalVirtual; 
            public UInt32 dwAvailVirtual;   

       }
        [DllImport("CoreDll.dll")]
        public static extern void GlobalMemoryStatus
        (
            ref MEMORYSTATUS lpBuffer
        );
        [DllImport("CoreDll.dll")]
        public static extern int GetSystemMemoryDivision
        (
            ref UInt32 lpdwStorePages,
            ref UInt32 lpdwRamPages,
            ref UInt32 lpdwPageSize
        );
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("aaaaaaaaaaaaaaaaaaaaa");
            UInt32 storePages = 0;
            UInt32 ramPages = 0;
            UInt32 pageSize = 0;
            int res = GetSystemMemoryDivision(ref storePages,
                ref ramPages, ref pageSize);

            // Call the native GlobalMemoryStatus method
            // with the defined structure.
            MEMORYSTATUS memStatus = new MEMORYSTATUS();
            GlobalMemoryStatus(ref memStatus);

            // Use a StringBuilder for the message box string.
            StringBuilder MemoryInfo = new StringBuilder();
            MemoryInfo.Append("Memory Load: "
                + memStatus.dwMemoryLoad.ToString() + "/n");
            MemoryInfo.Append("Total Physical: "
                + memStatus.dwTotalPhys.ToString() + "/n");
            MemoryInfo.Append("Avail Physical: "
                + memStatus.dwAvailPhys.ToString() + "/n");
            MemoryInfo.Append("Total Page File: "
                + memStatus.dwTotalPageFile.ToString() + "/n");
            MemoryInfo.Append("Avail Page File: "
                + memStatus.dwAvailPageFile.ToString() + "/n");
            MemoryInfo.Append("Total Virtual: "
                + memStatus.dwTotalVirtual.ToString() + "/n");
            MemoryInfo.Append("Avail Virtual: "
                + memStatus.dwAvailVirtual.ToString() + "/n");
            MemoryInfo.Append("Length:"
                + memStatus.dwLength.ToString() + "/n");
            // Show the available memory.
            MessageBox.Show(MemoryInfo.ToString());

        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值