如何精确评估Delphi程序运行中的内存使用峰值?

2026-04-10 18:112阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计315个文字,预计阅读时间需要2分钟。

如何精确评估Delphi程序运行中的内存使用峰值?

我正在使用Delphi 2009进行编码,想知道程序使用了多少内存。由于内存管理器在释放对象时不会将未使用的内存释放回操作系统,因此它可能会在内存中缓存以供下次使用。我的问题是,这是否会发生。

我正在使用Delphi 2009进行编码,我想知道程序使用了多少内存.由于内存管理器在释放对象时不会将未使用的内存释放回操作系统,因此它可能会在内存中缓存以供下次使用.我的问题是,是否有可能知道程序使用了多少内存.它应该排除内存管理器中缓存的内存.谢谢. 我有一个例程,在调试模式下调用FastMM函数来获取内存(正如David建议的那样).当没有安装FastMM时,即在我的发布模式下,我使用以下代码,只需要参考Delphi的System单元:

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.

如何精确评估Delphi程序运行中的内存使用峰值?

本文共计315个文字,预计阅读时间需要2分钟。

如何精确评估Delphi程序运行中的内存使用峰值?

我正在使用Delphi 2009进行编码,想知道程序使用了多少内存。由于内存管理器在释放对象时不会将未使用的内存释放回操作系统,因此它可能会在内存中缓存以供下次使用。我的问题是,这是否会发生。

我正在使用Delphi 2009进行编码,我想知道程序使用了多少内存.由于内存管理器在释放对象时不会将未使用的内存释放回操作系统,因此它可能会在内存中缓存以供下次使用.我的问题是,是否有可能知道程序使用了多少内存.它应该排除内存管理器中缓存的内存.谢谢. 我有一个例程,在调试模式下调用FastMM函数来获取内存(正如David建议的那样).当没有安装FastMM时,即在我的发布模式下,我使用以下代码,只需要参考Delphi的System单元:

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.

如何精确评估Delphi程序运行中的内存使用峰值?