8. Show how much memory the program uses.

Source: Internet
Author: User

Method One: Add Unit psapiprocedure Tform1.tmr1timer (sender:tobject); Begin EDT1. text:= format (' Memory use:%d KB ', [Getprocessmemuse (GetCurrentProcessId)]);//Method One End;function    Tform1.getprocessmemuse (pid:cardinal): Cardinal; Method one varpmc:pprocess_memory_counters;  Uses psapiprochandle:hwnd;isize:dword;begin Result: = 0;  Isize: = SizeOf (_process_memory_counters);  Getmem (PMC, isize);    Try PMC^.CB: = isize; Prochandle: = OpenProcess (process_query_information or Process_vm_read, False, PID); The handle of the process object is obtained by the PID if Getprocessmemoryinfo (Prochandle, PMC, isize) then Result: = pmc^.    WorkingSetSize;  Result: =result div 1024;  Finally Freemem (PMC); end;end;//********************************************* method Two: To add Unit Psapi, Tlhelp32;procedure TForm1.tmr1Timer (Sender : TObject); var str,str2:string;begin if (getprocessmemorysize (' Proj1.exe ', str,str2) then//method two parameters to write program name, bad begin ED T2.  Text: = ' Current Memory usage: ' + str + ' KB '; End End;function tform1.getprocessmemorysize (processname:string; var Size,//Method two pn:string): Boolean;varpprocess:thandle; Memsize,t:integer;hprocsnap:thandle; ppmcsize:cardinal;pe32:tprocessentry32;  Ppmc:pprocess_memory_counters;begin ppmcsize: = SizeOf (process_memory_counters);  Getmem (PPMC, ppmcsize);  Ppmc^.cb:= ppmcsize;  Hprocsnap:=createtoolhelp32snapshot (th32cs_snapall, 0);  If Hprocsnap=invalid_handle_value then Exit;  Pe32.dwsize:=sizeof (PROCESSENTRY32); If Process32First (hprocsnap,pe32) =true then and Process32Next (HPROCSNAP,PE32) =true do BEGIN if UPP Ercase (Pe32.szexefile) =uppercase (ProcessName) THEN BEGIN Pprocess:=openprocess (process_all_access,fals            E, Pe32.th32processid); if (Getprocessmemoryinfo (pprocess,ppmc,ppmcsize)) THEN BEGIN memsize:=ppmc^.               WorkingSetSize Div 1024;               t:= Length (IntToStr (memsize))-2;               Size:=inttostr (memsize);               Insert (', ', size,t);               Pn:=processname;       Freemem (PPMC);        Result:=true;               End ELSE begin FREEMEM (PPMC);             Result:=false;          End      End  End  CloseHandle (pprocess); CloseHandle (hprocsnap); end;

  

8. Show how much memory the program uses.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.