111,126
社区成员
发帖
与我相关
我的任务
分享[StructLayoutAttribute(LayoutKind.Sequential)]
public struct MemoryStatus
{
uint dwMemoryLoad; // 物理内存使用率
uint dwTotalPhys; // 物理内存总数
uint dwAvailPhys; // 物理内存可用数
uint dwTotalPageFile;// 页文件总数
uint dwAvailPageFile;// 页文件用数
uint dwTotalVirtual; // 虚拟内存总数
uint dwAvailVirtual; // 虚拟内存可用数
}
byte[] bytes = 你接收到的字节数组;
Type type = typeof(MemoryStatus);
int size = Marshal.SizeOf(type);
IntPtr p = Marshal.AllocHGlobal(size);
Marshal.Copy(bytes, 0, p, size);
MemoryStatus obj = (MemoryStatus)Marshal.PtrToStructure(p, type); //obj 就是转换后得到的结构
Marshal.FreeHGlobal(p);
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct MemoryStatus {
/// DWORD->unsigned int
public uint dwMemoryLoad;
/// DWORD->unsigned int
public uint dwTotalPhys;
/// SIZE_T->ULONG_PTR->unsigned int
public uint dwAvailPhys;
/// SIZE_T->ULONG_PTR->unsigned int
public uint dwTotalPageFile;
/// SIZE_T->ULONG_PTR->unsigned int
public uint dwAvailPageFile;
/// SIZE_T->ULONG_PTR->unsigned int
public uint dwTotalVirtual;
/// SIZE_T->ULONG_PTR->unsigned int
public uint dwAvailVirtual;
}