Rom*_*sky 6 delphi memory-management fastmm
我如何获得由FastMM分配的内存总量?
我试过了:
function GetTotalAllocatedMemory: Cardinal;
var
MMState: TMemoryManagerState;
begin
GetMemoryManagerState(MMState);
Result := MMState.TotalAllocatedMediumBlockSize + MMState.TotalAllocatedLargeBlockSize;
end;
Run Code Online (Sandbox Code Playgroud)
这是对的吗?
无论如何它会返回奇怪的东西.它比我在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;
Run Code Online (Sandbox Code Playgroud)