用GetProcessMemoryInfo获取的内存占用和任务管理器显示不一样? 用什么取才和任务管理器一致?现在到百度已查不到什么有用的信息了。 function GetPIdMemUsage(PID: dword): SIZE_T; var memCounters: _PROCESS_MEMORY_COUNTERS; h: THandle; //cardinal; begin result:=0; ZeroMemory(@memCounters, sizeof(memCounters)); h := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID); if h <> 0 then begin memCounters.cb := sizeof(memCounters); if not GetProcessMemoryInfo(h, @memCounters, sizeof(memCounters)) then result := 0 // showmessage('Coulnd''t get memory info!') else begin // showmessage('Current : '+inttostr(memCounters.WorkingSetSize shr 10)+' K'#13#10+'Peak : '+inttostr(memCounters.PeakWorkingSetSize shr 10 )+' K'#13#10+'Pagefile : '+inttostr(memCounters.PageFaultCount shr 10)+' K'); result :=memCounters.PeakWorkingSetSize shr 10;// memCounters.WorkingSetSize shr 10; end; closehandle(h); end; end;
----------------------------------------------
永远是DELPHI初学者。
工作集 分页池 非分页池 pagefile 工作集是在给定时间以物理方式映射到进程上下文的内存量。 分页池中的内存是系统内存,可以在不使用分页 () 传输到磁盘上的分页文件。 非分页池中的内存是系统内存,只要分配了相应的对象,系统内存就无法分页到磁盘。 页面文件使用情况表示系统分页文件中为进程预留的内存量。 当内存使用率过高时,虚拟内存管理器会将所选内存分页到磁盘。 当线程需要不在内存中的页时,内存管理器会从分页文件中重新加载它。
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
var pmc: PPROCESS_MEMORY_COUNTERS; cb: Integer; begin cb := SizeOf(_PROCESS_MEMORY_COUNTERS); GetMem(pmc, cb); pmc^.cb := cb; if GetProcessMemoryInfo(GetCurrentProcess(), pmc, cb) then ShowMessage(IntToStr(pmc^.WorkingSetSize) + ' Bytes') else ShowMessage('Unable to get process info'); FreeMem(pmc); end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3