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

MEMORYSTATUS (Structures)
 
.
Summary
Summary
Contains information about the current state of both physical and virtual memory.

Notes:

The CLR offer us no way to tell us that memory is getting tight. Many think this API provides the best solution. This is mentioned by Jeffrey Richter in his book 'CLR via C#' ISBN: 0-7356-2163-2. It is useful in determining if your system is under excessive memory load by looking at the dwMemoryLoad member of the MEMORYSTATUSEX structure. If this value is > 80 (per Mr. Richter in his discussion of Garbage Collection), it is an indication that you might want to consider converting some strong references into weak references. Remember that a weakreference type will be collected when Generation 0 is full, so it is not a good technique for caching (as many seem to think).

C# Definition:

       /// <summary>
    /// contains information about the current state of both physical and virtual memory, including extended memory
     /// <summary>
    /// The MEMORYSTATUS structure contains information about the current state of both physical and virtual memory.
    /// </summary>
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public class MEMORYSTATUSEX
    public struct MEMORYSTATUS
    {
        /// <summary>
        /// Size of the structure, in bytes. You must set this member before calling GlobalMemoryStatusEx.
        /// Size of the MEMORYSTATUS data structure, in bytes. You do not need to set this member before calling the GlobalMemoryStatus function; the function sets it.
        /// </summary>
        public uint dwLength;

        /// <summary>
        /// Number between 0 and 100 that specifies the approximate percentage of physical memory that is in use (0 indicates no memory use and 100 indicates full memory use).
        /// Windows NT:  Percentage of approximately the last 1000 pages of physical memory that is in use.
        /// </summary>
        public uint dwMemoryLoad;

        /// <summary>
        /// Total size of physical memory, in bytes.
        /// Total size of physical memory, in bytes.
        /// </summary>
        public ulong ullTotalPhys;
        public uint dwTotalPhys;

        /// <summary>
        /// Size of physical memory available, in bytes.
        /// Size of physical memory available, in bytes
        /// </summary>
        public ulong ullAvailPhys;
        public uint dwAvailPhys;

        /// <summary>
        /// Size of the committed memory limit, in bytes. This is physical memory plus the size of the page file, minus a small overhead.
        /// Size of the committed memory limit, in bytes.
        /// </summary>
        public ulong ullTotalPageFile;
        public uint dwTotalPageFile;

        /// <summary>
        /// Size of available memory to commit, in bytes. The limit is ullTotalPageFile.
        /// Size of available memory to commit, in bytes.
        /// </summary>
        public ulong ullAvailPageFile;
        public uint dwAvailPageFile;

        /// <summary>
        /// Total size of the user mode portion of the virtual address space of the calling process, in bytes.
        /// </summary>
        public ulong ullTotalVirtual;
        public uint dwTotalVirtual;

        /// <summary>
        /// Size of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process, in bytes.
        /// </summary>
        public ulong ullAvailVirtual;
        public uint dwAvailVirtual;

        /// <summary>
        /// Size of unreserved and uncommitted memory in the extended portion of the virtual address space of the calling process, in bytes.
        /// </summary>
        public ulong ullAvailExtendedVirtual;
    } // class MEMORYSTATUS

VB Definition:

      ''' <summary>
      ''' The MEMORYSTATUS structure contains information about the current state of both physical and virtual memory.
      ''' </summary>
      <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
      Public Class MEMORYSTATUS
        ''' <summary>
        ''' Size of available memory to commit, in bytes.
        ''' </summary>
        Public dwAvailPageFile As UInt32
        ''' <summary>
        ''' Size of physical memory available, in bytes
        ''' </summary>
        Public dwAvailPhys As UInt32
        ''' <summary>
        ''' Size of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process, in bytes.
        ''' </summary>
        Public dwAvailVirtual As UInt32
        ''' <summary>
        ''' Size of the MEMORYSTATUS data structure, in bytes. You do not need to set this member before calling the GlobalMemoryStatus function; the function sets it.
        ''' </summary>
        Public dwLength As UInt32
        ''' <summary>
        ''' Number between 0 and 100 that specifies the approximate percentage of physical memory that is in use (0 indicates no memory use and 100 indicates full memory use).
        ''' Windows NT:  Percentage of approximately the last 1000 pages of physical memory that is in use.
        ''' </summary>
        Public dwMemoryLoad As UInt32
        ''' <summary>
        ''' Size of the committed memory limit, in bytes.
        ''' </summary>
        Public dwTotalPageFile As UInt32
        ''' <summary>
        ''' Total size of physical memory, in bytes.
        ''' </summary>
        Public dwTotalPhys As UInt32
        ''' <summary>
        ''' Total size of the user mode portion of the virtual address space of the calling process, in bytes.
        ''' </summary>
        Public dwTotalVirtual As UInt32
      End Class

        /// <summary>
        /// Initializes a new instance of the <see cref="T:MEMORYSTATUSEX"/> class.
        /// </summary>
        public MEMORYSTATUSEX()
        {
        this.dwLength = (uint)Marshal.SizeOf(typeof(NativeMethods.MEMORYSTATUSEX));
        }
       }

User-Defined Field Types:

None.

       //
       // Alternate, Structure Version.  This One Allows Correct Marshalling As A "ref" Parameter,
       // But You Have To Ensure The Value Of dwLength Gets Set Correctly Via A Wrapper Method.
       //
    /// <summary>Contains information about the current state of both physical and virtual
    /// memory, including extended memory. The GlobalMemoryStatusEx function stores
    /// information in this structure.</summary>
    /// <remarks>MEMORYSTATUSEX reflects the state of memory at the time of the call. It also
    /// reflects the size of the paging file at that time. The operating system can enlarge
    /// the paging file up to the maximum size set by the administrator.</remarks>
    [StructLayout( LayoutKind.Sequential )]
    public struct MEMORYSTATUSEX
    {
        /// <summary>The size of the structure, in bytes. You must set this member before
        /// calling GlobalMemoryStatusEx.</summary>
        public uint dwLength;
        /// <summary>A number between 0 and 100 that specifies the approximate percentage
        /// of physical memory that is in use (0 indicates no memory use and 100
        /// indicates full memory use).</summary>
        public uint dwMemoryLoad;
        /// <summary>The amount of actual physical memory, in bytes.</summary>
        public ulong ullTotalPhys;
        /// <summary>The amount of physical memory currently available, in bytes. This is the
        /// amount of physical memory that can be immediately reused without having to write
        /// its contents to disk first. It is the sum of the size of the standby, free, and
        /// zero lists.</summary>
        public ulong ullAvailPhys;
        /// <summary>The current committed memory limit for the system or the current process,
        /// whichever is smaller, in bytes. To get the system-wide committed memory limit,
        /// call GetPerformanceInfo.</summary>
        public ulong ullTotalPageFile;
        /// <summary>The maximum amount of memory the current process can commit, in bytes.
        /// This value is equal to or smaller than the system-wide available commit value.
        /// To calculate the system-wide available commit value, call GetPerformanceInfo
        /// and subtract the value of CommitTotal from the value of CommitLimit.</summary>
        public ulong ullAvailPageFile;
        /// <summary>The size of the user-mode portion of the virtual address space of the
        /// calling process, in bytes. This value depends on the type of process, the type
        /// of processor, and the configuration of the operating system. For example, this
        /// value is approximately 2 GB for most 32-bit processes on an x86 processor and
        /// approximately 3 GB for 32-bit processes that are large address aware running
        /// on a system with 4-gigabyte tuning enabled.</summary>
        public ulong ullTotalVirtual;
        /// <summary>The amount of unreserved and uncommitted memory currently in the user-mode
        /// portion of the virtual address space of the calling process, in bytes.</summary>
        public ulong ullAvailVirtual;
        /// <summary>Reserved. This value is always 0.</summary>
        public ulong ullAvailExtendedVirtual;
    }

Notes:

Also see MEMORYSTATUSEX, GlobalMemoryStatus, GlobalMemoryStatusEx.

VB Definition:

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Class MEMORYSTATUSEX

        ''' <summary>
        ''' Initializes a new instance of the <see cref="T:MEMORYSTATUSEX" /> class.
        ''' </summary>
        Public Sub New()
        Me.dwLength = CType(Marshal.SizeOf(GetType(MEMORYSTATUSEX)), UInt32)
        End Sub
        ' Fields
        ''' <summary>
        ''' Size of the structure, in bytes. You must set this member before calling GlobalMemoryStatusEx.
        ''' </summary>
        Public dwLength As UInt32
        ''' <summary>
        ''' Number between 0 and 100 that specifies the approximate percentage of physical memory that is in use (0 indicates no memory use and 100 indicates full memory use).
        ''' </summary>
        Public dwMemoryLoad As UInt32
        ''' <summary>
        ''' Total size of physical memory, in bytes.
        ''' </summary>
        Public ullTotalPhys As UInt64
        ''' <summary>
        ''' Size of physical memory available, in bytes.
        ''' </summary>
        Public ullAvailPhys As UInt64
        ''' <summary>
        ''' Size of the committed memory limit, in bytes. This is physical memory plus the size of the page file, minus a small overhead.
        ''' </summary>
        Public ullTotalPageFile As UInt64
        ''' <summary>
        ''' Size of available memory to commit, in bytes. The limit is ullTotalPageFile.
        ''' </summary>
        Public ullAvailPageFile As UInt64
        ''' <summary>
        ''' Total size of the user mode portion of the virtual address space of the calling process, in bytes.
        ''' </summary>
        Public ullTotalVirtual As UInt64
        ''' <summary>
        ''' Size of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process, in bytes.
        ''' </summary>
        Public ullAvailVirtual As UInt64
        ''' <summary>
        ''' Size of unreserved and uncommitted memory in the extended portion of the virtual address space of the calling process, in bytes.
        ''' </summary>
        Public ullAvailExtendedVirtual As UInt64
    End Class

User-Defined Field Types:

None.

Notes:

See
Documentation
Documentation

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

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