gpt4 book ai didi

delphi - FastMM:分配的总内存

转载 作者:行者123 更新时间:2023-12-03 14:57:20 26 4
gpt4 key购买 nike

如何获取 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;

关于delphi - FastMM:分配的总内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5470199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com