Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

GlobalMemoryStatusEx (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);

User-Defined Types:

MEMORYSTATUSEX

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

private void DisplayMemory()

        {
            string[] Drives = System.IO.Directory.GetLogicalDrives();
            long tm = System.GC.GetTotalMemory(true);
            UInt64 UserAvailable=0,Capacity=0,Available=0;
            if(Drives!=null)
            {
                int retval = GetDiskFreeSpaceExA(Drives[0],ref UserAvailable,ref Capacity,ref Available);
                this.lblDiskFree.Text = Available.ToString();
                this.lblDiskTotal.Text = Capacity.ToString();
            }
            MEMORYSTATUSEX msex=new MEMORYSTATUSEX();
            msex.dwLength = (uint)Marshal.SizeOf(msex);
            int retval2 = GlobalMemoryStatusEx(ref msex);
            this.lblMemoryFree.Text = msex.ullAvailPhys.ToString();
            this.lblMemoryTotal.Text = msex.ullTotalPhys.ToString();
        }

        private struct MEMORYSTATUSEX
                {
                    public uint dwLength;  
                    public uint dwMemoryLoad;  
                    public UInt64 ullTotalPhys;  
                    public UInt64 ullAvailPhys;  
                    public UInt64 ullTotalPageFile;  
                    public UInt64 ullAvailPageFile;  
                    public UInt64 ullTotalVirtual;  
                    public UInt64 ullAvailVirtual;  
                    public UInt64 ullAvailExtendedVirtual;
                };

        [DllImport("kernel32.dll")]
        private static extern int GetDiskFreeSpaceExA(  string lpDirectoryName,
            ref System.UInt64 lpFreeBytesAvailable,
            ref System.UInt64 lpTotalNumberOfBytes,
            ref System.UInt64 lpTotalNumberOfFreeBytes
            );

        [DllImport("kernel32.dll")]
        private static extern int GlobalMemoryStatusEx(
            ref MEMORYSTATUSEX msex
            );

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions