Results 1 to 6 of 6

Thread: Resource consumption awareness

  1. #1

    Resource consumption awareness

    If I hit <CTRL>-<ALT>-<DEL>, I can bring up the Task Manager, which tells me how much memory each program is using and how much CPU% it's consuming. How can my program get access to this data? I want to be able to optionally pre-load certain data before it's needed, but put a cap on it so it won't use up too much RAM. For this, I need to know the total amount of RAM the program's using.

  2. #2

    Resource consumption awareness

    there are some winapi functions to retreive this kind of info, but i don't remember now =X
    From brazil (:

    Pascal pownz!

  3. #3

    Resource consumption awareness

    Yeah, I figured there would be. Does anyone know what it is?

  4. #4

    Resource consumption awareness

    Found this with a little google (didn't test it though):

    Code:
    uses psAPI;
    
    procedure TForm1.Button1Click&#40;Sender&#58; TObject&#41;;
    var
      pmc&#58; PPROCESS_MEMORY_COUNTERS;
      cb&#58; Integer;
    begin
      cb &#58;= SizeOf&#40;_PROCESS_MEMORY_COUNTERS&#41;;
      GetMem&#40;pmc, cb&#41;;
      pmc^.cb &#58;= cb;
      if GetProcessMemoryInfo&#40;GetCurrentProcess&#40;&#41;, pmc, cb&#41; then
        Label1.Caption &#58;= IntToStr&#40;pmc^.WorkingSetSize&#41; + ' Bytes'
      else
        Label1.Caption &#58;= 'Unable to retrieve memory usage structure';
    
      FreeMem&#40;pmc&#41;;
    end;
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  5. #5

    Resource consumption awareness

    [pascal]
    uses
    psAPI;

    function GetProcessMemorySize(sProcessName: string; var cMemSize: Cardinal): boolean;
    var
    hWndHandle, hProcID, hTmpHdn : HWND;
    pPMC: PPROCESS_MEMORY_COUNTERS;
    cSize: Cardinal;
    begin
    Result := False;

    hWndHandle := FindWindow(nil, PChar(sProcessName));
    if hWndHandle = 0 then exit;

    cSize := SizeOf(PROCESS_MEMORY_COUNTERS);
    GetMem(pPMC, cSize);
    pPMC^.cb := cSize;
    GetWindowThreadProcessId(hWndHandle, @hProcID);

    hTmpHdn := OpenProcess(PROCESS_ALL_ACCESS, False, hProcID);
    if GetProcessMemoryInfo(hTmpHdn, pPMC, cSize) then
    cMemSize := pPMC^.WorkingSetSize
    else
    cMemSize := 0;

    FreeMem(pPMC);
    Result := True;
    end;
    [/pascal]

    usage:

    [pascal]
    var
    cSize: Cardinal;
    begin
    if GetProcessMemorySize('softwarename', cSize) then
    [/pascal]

    -Meka][Meka

  6. #6

    Resource consumption awareness

    Huehnerschaender: Thanks! That's just what I was looking for!

    Memphis: Thanks too, but... that's scary. I think I'll use Huehnerschaender's version.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •