我如何获得由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;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。