/// <summary>
/// This structure is defined at 88 bytes. However on Windows 7 it is 168 bytes.
/// It seems there is more info added but we don't know what it is. Be sure to
/// allocate at least 168 bytes to your buffer or it will likely fail.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SYSTEM_MEMORY_LIST_INFORMATION // Size=88
{
public UInt32 ZeroPageCount; // Size=4 Offset=0
public UInt32 FreePageCount; // Size=4 Offset=4
public UInt32 ModifiedPageCount; // Size=4 Offset=8
public UInt32 ModifiedNoWritePageCount; // Size=4 Offset=12
public UInt32 BadPageCount; // Size=4 Offset=16
/// <summary>There are 8 priority levels, so array of 8</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public UInt32[] PageCountByPriority; // Size=32 Offset=20
/// <summary>There are 8 priority levels, so array of 8</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public UInt32[] RepurposedPagesByPriority; // Size=32 Offset=52
public UInt32 ModifiedPageCountPageFile; // Size=4 Offset=84
}
Declare Function SYSTEM_MEMORY_LIST_INFORMATION Lib "ntdll.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
None.
Please add some!
public void Test()
{
UInt32
result = 0;
NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION
MemoryList;
UInt32
returnSize;
Int32[]
arr = new Int32[] { (Int32)Commands.MEMORYLIST };
IntPtr
buff = Marshal.AllocHGlobal(1024); // should be more than adequate
try
{
result = (UInt32)NativeMethods.NtQuerySystemInformation(NativeMethods.SYSTEM_INFORMATION_CLASS.SystemMemoryListInformation, buff, result, out returnSize);
if (result != 0)
// Most likely error is InfoLengthMismatch = 0xc0000004 -- meaning you need to make the buffer larger
throw new System.ComponentModel.Win32Exception(((NativeMethods.NtStatus)result).ToString());
MemoryList = (NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION)Marshal.PtrToStructure(buff, typeof(NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION));
}
finally
{
Marshal.FreeHGlobal(buff);
}
}