RSS订阅 | 匿名投稿
您的位置:网站首页 > 进程 > 正文

delphi 取得当前进程占用内存及线程数

作者:admin 来源: 日期:2018/2/11 13:11:16 人气: 标签:

单元 uses TLhelp32;

// 取得当前进程占用内存
function CurrentMemoryUsage: Cardinal;
var
  pmc: TProcessMemoryCounters;
begin
  pmc.cb := SizeOf(pmc);
  if GetProcessMemoryInfo(GetCurrentProcess, @pmc, SizeOf(pmc)) then
    result := pmc.WorkingSetSize
  else
    RaiseLastOSError;
end;

// 取得当前进程的线程数
function GetProcessThreadCount: integer;
var
  SnapProcHandle: THandle;
  ThreadEntry: TThreadEntry32;
  Next: boolean;
begin
  result := 0;
  SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
  if SnapProcHandle <> THandle(-1) then
  begin
    ThreadEntry.dwSize := SizeOf(ThreadEntry);
    Next := Thread32First(SnapProcHandle, ThreadEntry);
    while Next do
    begin
      if (ThreadEntry.th32OwnerProcessID = GetCurrentProcessId) then
        result := result + 1;
      Next := Thread32Next(SnapProcHandle, ThreadEntry);
    end;
    CloseHandle(SnapProcHandle);
  end;
end;

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:没有资料