我使用Delphi 2009进行编码,我想知道程序使用了多少内存。因为内存管理器在释放对象时不会将未使用的内存释放回操作系统,因此它可能会缓存在内存中以供下次使用。我的问题是如果有一种可能的方法来知道程序使用了多少内存。它应该排除在内存管理器中缓存的内存。谢谢。如何测量内存使用情况
4
A
回答
1
我有一个例程,在调试模式下调用FastMM函数来获取内存使用(如David建议)。当我在释放模式没有安装FastMM即我用下面的代码,只需要德尔福的系统单元的参考:
function GetAllocatedMemoryBytes_NativeMemoryManager : NativeUInt;
// Get the size of all allocations from the memory manager
var
MemoryManagerState: TMemoryManagerState;
SmallBlockState: TSmallBlockTypeState;
i: Integer;
begin
GetMemoryManagerState(MemoryManagerState);
Result := 0;
for i := low(MemoryManagerState.SmallBlockTypeStates) to
high(MemoryManagerState.SmallBlockTypeStates) do
begin
SmallBlockState := MemoryManagerState.SmallBlockTypeStates[i];
Inc(Result,
SmallBlockState.AllocatedBlockCount*SmallBlockState.UseableBlockSize);
end;
Inc(Result, MemoryManagerState.TotalAllocatedMediumBlockSize);
Inc(Result, MemoryManagerState.TotalAllocatedLargeBlockSize);
end;
我用XE2,所以你可能需要NativeUInt改为Int64的。
+0
NativeInt在delphi 2009上存在,但我认为它是NativeUInt,用于分配超过2GB内存的32位进程。 – 2012-03-10 07:37:41
相关问题
- 1. Java测量内存使用情况的方法如何?
- 2. 如何测量Linux中OpenMP代码的内存使用情况?
- 3. 如何测量python中对象的内存使用情况?
- 4. 如何测量Firefox附加内存使用情况
- 5. 如何测量F#代码的CPU和内存使用情况?
- 6. 如何测量代码的内存使用情况?
- 7. 如何在不分配内存的情况下测量.net应用程序的内存使用情况?
- 8. 使用process.WorkingSet64测量内存使用情况的异常
- 9. 如何测量硒的使用情况?
- 10. 如何测量使用Werkzeug/Flask时Web请求的内存使用情况?
- 11. gdb巨量内存使用情况
- 12. 测量分布式应用程序的内存使用情况
- 13. 用于测量CPU和内存使用情况的RRD
- 14. 测量ios应用程序的内存使用情况
- 15. 如何分析内存使用情况?
- 16. 测量Java程序内存使用情况的最佳方法?
- 17. Powershell。 C#测量PowerShell主机内存使用情况
- 18. 测量进程CPU和内存使用情况
- 19. Android的每个GC之后的内存使用情况测量
- 20. 内存使用情况
- 21. iphone内存使用情况
- 22. Tcl_Format内存使用情况
- 23. Silverlight内存使用情况
- 24. IronPython内存使用情况
- 25. Java内存使用情况
- 26. V8内存使用情况
- 27. Listview内存使用情况
- 28. Linux内存使用情况
- 29. Android内存使用情况
- 30. java内存使用情况
如果我没有记错,完整版的FastMM包含一个演示内存使用情况跟踪程序。这听起来像你所需要的。 – 2012-03-09 08:23:40
我觉得这个话题有几个问题。参见exampel http://stackoverflow.com/questions/4448129/why-doesnt-my-programs-memory-usage-return-to-normal-after-i-free-memory或http://stackoverflow.com/questions/4475592/how-to-convince-memory-manager-release-unused-memory – jpfollenius 2012-03-09 08:53:29
有人可以在http://stackoverflow.com/questions/4448129/why-doesnt-my中评论“Inside - Windows”的值-programs-memory-usage-return-to-normal-after-i-free-memory question – Branko 2012-03-09 10:48:45