探索虚拟内存
1得到系统信息
GetsystemInfo(LPSYSTEM_INFO os);
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId; // Obsolete field...do not use
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO, *LPSYSTEM_INFO;
2 虚拟内存状态
VOID
WINAPI
GlobalMemoryStatus(
__out LPMEMORYSTATUS lpBuffer
);
typedef struct _MEMORYSTATUS {
DWORD dwLength; // 在使用前必须用结构体大小来初始化
DWORD dwMemoryLoad; 内存使用百分率
SIZE_T dwTotalPhys; 物理内存总量
SIZE_T dwAvailPhys; 还剩余物理内存总量
SIZE_T dwTotalPageFile; 页面文件总量,包括虚拟内存和物理内存
SIZE_T dwAvailPageFile; 页面剩余量
SIZE_T dwTotalVirtual; 虚拟内存总量
SIZE_T dwAvailVirtual; 剩余虚拟内存量
} MEMORYSTATUS, *LPMEMORYSTATUS;
GetProcessMemoryInfo
得到进程的信息
PROCESS_MEMORY_COUNTERS_EX pmc = { sizeof(PROCESS_MEMORY_COUNTERS_EX) };
GetProcessMemoryInfo(GetCurrentProcess(), (PPROCESS_MEMORY_COUNTERS)&pmc, sizeof(pmc));
struct _PROCESS_MEMORY_COUNTERS_EX {
DWORD cb;
必须初始化为结构体大小
DWORD PageFaultCount;
页面错误
SIZE_T PeakWorkingSetSize;
高峰工作集
SIZE_T WorkingSetSize;
工作集
SIZE_T QuotaPeakPagedPoolUsage;
高峰页面池
SIZE_T QuotaPagedPoolUsage;
页面缓冲池
SIZE_T QuotaPeakNonPagedPoolUsage;
高峰非页面缓冲池
SIZE_T QuotaNonPagedPoolUsage;
非页面缓冲池
SIZE_T PagefileUsage;
页面文件大小
SIZE_T PeakPagefileUsage;
高峰页面文件大小
SIZE_T PrivateUsage;
私有数据
} PROCESS_MEMORY_COUNTERS_EX;
确定地址空间中的状态
VirtualQuery
The
VirtualQuery function provides information about a range of pages in the virtual address space of the calling process.
这个函数为调用进程提供指定区域的虚拟内存信息