FastMM:总分配内存

我如何获得由FastMM分配的内存总量? 我试过了:
function GetTotalAllocatedMemory: Cardinal;
var
  MMState: TMemoryManagerState;
begin
  GetMemoryManagerState(MMState);
  Result := MMState.TotalAllocatedMediumBlockSize + MMState.TotalAllocatedLargeBlockSize;
end;
这是对的吗? 无论如何它会返回奇怪的东西。它比我在Windows任务管理器中看到的值少5倍。我相信Delphi应用程序分配的内存量等于FastMM分配的内存加上一些系统开销。我错了吗?     
已邀请:
用这个:
//------------------------------------------------------------------------------  
// CsiGetApplicationMemory  
//  
// Returns the amount of memory used by the application (does not include  
// reserved memory)  
//------------------------------------------------------------------------------  
function CsiGetApplicationMemory: Int64;  
var  
  lMemoryState: TMemoryManagerState;  
  lIndex: Integer;  
begin  
  Result := 0;  

  // get the state  
  GetMemoryManagerState(lMemoryState);  

  with lMemoryState do begin  
    // small blocks  
    for lIndex := Low(SmallBlockTypeStates) to High(SmallBlockTypeStates) do  
      Inc(Result,  
          SmallBlockTypeStates[lIndex].AllocatedBlockCount *  
          SmallBlockTypeStates[lIndex].UseableBlockSize);  

    // medium blocks  
    Inc(Result, TotalAllocatedMediumBlockSize);  

    // large blocks  
    Inc(Result, TotalAllocatedLargeBlockSize);  
  end;  
end;
    
你正在比较苹果和橘子。 FastMM内存是通过FastMM分配的内存的netto使用。 这不包括至少这些: FastMM开销 由FastMM代表您分配的块的Windows开销 没有FastMM分配的东西的Windows开销(就像进程空间中DLL占用的空间) 用于GUI应用程序:代表您分配的可视对象的GDI,GDI +,DirectX,OpenGL和其他存储的开销。 --jeroen     
对于进程内存使用此:
//------------------------------------------------------------------------------
// 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;
    
我也遇到过这样的情况:   无论如何它会返回奇怪的东西。它比一个值小5倍   我可以在Windows任务管理器中看到。我相信的数量   由Delphi应用程序分配的内存等于FastMM分配   内存加上一些系统开销。我错了吗? 并浪费了几个小时试图找出所有记忆的位置。根据任务经理的说法,我的app占用了170 Mb,但FastMM的统计数据显示了已分配块的总大小~13 Mb:
12565K Allocated
160840K Overhead
7% Efficiency
(摘自FastMM
LogMemoryManagerStateToFile
程序输出)。最后我意识到这个巨大的开销是由FullDebug模式引起的。它为每个分配保留堆栈跟踪,所以如果你分配了很多微小的内存块(我的应用程序有UnicodeString x 99137,Unknown x 17014和~10000个Xml对象),开销变得可怕。删除FullDebug模式会将内存消耗恢复为正常值。 希望这有助于某人。     

要回复问题请先登录注册