FastMM:总分配内存 [英] FastMM: Total Allocated Memory
本文介绍了FastMM:总分配内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试过:
function GetTotalAllocatedMemory:Cardinal;
var
MMState:TMemoryManagerState;
开始
GetMemoryManagerState(MMState);
结果:= MMState.TotalAllocatedMediumBlockSize + MMState.TotalAllocatedLargeBlockSize;
结束
是否正确?
无论如何返回一些奇怪的东西。它比Windows任务管理器中可以看到的值少5倍。我相信Delphi应用程序分配的内存量等于FastMM分配的内存加上一些系统开销。我错了吗?
解决方案
使用这个:
// ------------------------------------------ ------------------------------------
// CsiGetApplicationMemory
//
//返回应用程序使用的内存量(不包括
//保留内存)
// ----------------- -------------------------------------------------- -----------
函数CsiGetApplicationMemory:Int64;
var
lMemoryState:TMemoryManagerState;
lIndex:整数;
begin
结果:= 0;
//获取状态
GetMemoryManagerState(lMemoryState);
with lMemoryState do begin
// small blocks
for lIndex:= Low(SmallBlockTypeStates)to High(SmallBlockTypeStates)do
Inc(Result,
SmallBlockTypeStates [lIndex] .AllocatedBlockCount *
SmallBlockTypeStates [lIndex] .UseableBlockSize);
//中块
Inc(Result,TotalAllocatedMediumBlockSize);
//大块
Inc(Result,TotalAllocatedLargeBlockSize);
结束
结束
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?
解决方案
Use this:
//------------------------------------------------------------------------------
// 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:总分配内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文