Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FastMM: Total Allocated Memory

How could I get the total amount of memory, that allocated by FastMM?

I've tried that:

function GetTotalAllocatedMemory: Cardinal;
var
  MMState: TMemoryManagerState;
begin
  GetMemoryManagerState(MMState);
  Result := MMState.TotalAllocatedMediumBlockSize + MMState.TotalAllocatedLargeBlockSize;
end;

Is it correct?

Anyways it returns something strange. It 5 times less than a value which I can see in Windows task manager. I believe that the amount of memory allocated by a Delphi application equals FastMM allocated memory plus some system overhead. Am I wrong?

like image 219
Roman Yankovsky Avatar asked Mar 29 '11 09:03

Roman Yankovsky


2 Answers

For the process memory use this:

//------------------------------------------------------------------------------
// CsiGetProcessMemory
//
// Return the amount of memory used by the process
//------------------------------------------------------------------------------
function CsiGetProcessMemory: Int64;
var
  lMemoryCounters: TProcessMemoryCounters;
  lSize: Integer;
begin
  lSize := SizeOf(lMemoryCounters);
  FillChar(lMemoryCounters, lSize, 0);
  if GetProcessMemoryInfo(CsiGetProcessHandle, @lMemoryCounters, lSize) then
    Result := lMemoryCounters.PageFileUsage
  else
    Result := 0;
end;
like image 164
Misha Avatar answered Nov 04 '22 11:11

Misha


You are comparing apples and oranges.

FastMM memory is netto usage of memory allocated through FastMM.

This does not include at least these:

  • FastMM overhead
  • Windows overhead of blocks allocated by FastMM on your behalf
  • Windows overhead of things not allocated by FastMM (like the space occupied by DLL's in your process space)
  • for GUI apps: overhead of GDI, GDI+, DirectX, OpenGL and other storage for visual objects allocated on your behalf.

--jeroen

like image 24
Jeroen Wiert Pluimers Avatar answered Nov 04 '22 12:11

Jeroen Wiert Pluimers