[转] FastMM、FastCode、FastMove的使用

http://blog.csdn.net/akof1314/article/details/6524767

 FastMM是一个替换Embarcadero Delphi Win32应用程序的快速内存管理器,以及可以在多线程下使用,不容易产生内存碎片,并且无需使用外部DLL文件就可以支持共享内存。

使用方法:
1.对IDE加速
    解压之后,文件夹".../FastMM/Replacement BorlndMM DLL/Delphi/Precompiled/for Delphi IDE/Performance"下的"BorlndMM.dll"拷贝到Delphi安装目录下的".../Borland/Delphi7/Bin"进行覆盖安装(最好先备份下)。
2.对应用程序加速
    打开Delphi IDE,将文件夹".../FastMM"添加到"Environment Options"下的"Library"中。然后再在具体项目工程中,在菜单栏→"Project"→"View Source"下,将"FastMM4.pas"单元添加到"uses"下的第一个位置。若需要内存报告消息为中文的话,将文件".../FastMM/Translations/Chinese (Simplified)/FastMM4Messages.pas"替换文件".../FastMM/FastMM4Messages.pas"即可。

下面测试内存泄露报告:
1)新建一个Delphi应用程序,在工程文件将"FastMM4.pas"单元添加到"uses"下的第一个位置;
2)添加一个按钮,按钮单击事件如下:

1
2
3
4
5
6
 procedure TForm1.btn1Click(Sender: TObject); 
var 
  sl: TStrings; 
begin 
  sl := TStringList.Create; 
end; 

3)运行程序,单击按钮,退出程序,观察结果如下图所示:

     从上面可以看到有报告内存泄露,并且提示TStringList.泄露,提醒要得到详细的内存泄露信息,需开启"FullDebugMode"和"LogMemoryLeakDetailToFile"条件编译开关。打开文件".../FastMM/FastMM4Options.inc",在文件末尾添加以下代码:

{快速配置发布版本和调试版本} 
{$ifdef Release} 
  {发布版本请设置} 
  {$undef FullDebugMode} 
  {$undef CheckHeapForCorruption} 
  {$define ASMVersion} 
  {$undef EnableMemoryLeakReporting} 
  {$undef UseOutputDebugString} 
{$else} 
  {调试版本请设置} 
  {$define FullDebugMode} 
  {$define EnableMemoryLeakReporting} 
  {$define UseOutputDebugString} 
{$endif} 

再将文件".../FastMM/FullDebugMode DLL/Precompiled/FastMM_FullDebugMode.dll"拷贝到工程可执行程序目录下,运行程序,单击按钮,观察结果如下图所示:

在工程目录下有日志文件"Project1_MemoryManager_EventLog.txt"记录内存泄露详细信息,如下图所示:

若是发布版本的话,关闭调试模式,在菜单栏→"Project"→"Options"→"Directories/Conditionals"→"Conditionals"下,定义一个条件编译"Release",如下图所示:

再次运行程序,单击按钮,观察结果,已经无内存泄露报告提示框了。注意以上仅在IDE中调试程序有检查内存泄露,若是要在脱离IDE运行程序也检测内存泄露,请关闭选项  {$define RequireDebuggerPresenceForLeakReporting},此项默认开启。


    FastCode为Delphi社区提供高度优化的函数,此函数比Delphi运行时库函数、VCL函数以及它们的扩展函数更快。FastMove替换所有的system.move调用,因为它有更快的速度。

使用方法:
    解压之后,将FastMove放到FastCode文件夹下,这样就只需引用一个环境路径,将".../FastCode"添加到"Environment Options"下的"Library"中。然后再在具体项目工程中,在菜单栏→"Project"→"View Source"下,将"FastCode.pas"和"FastMove.pas"单元添加到"uses"下的第一个位置,如下所示:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
 program Project1; 
 
uses 
  FastMM4,     {假如有FastMM的话,放在第一个位置} 
  FastCode, 
  FastMove, 
  Forms, 
  Unit1 in 'Unit1.pas' {Form1}; 
 
{$R *.res} 
 
begin 
  Application.Initialize; 
  Application.CreateForm(TForm1, Form1); 
  Application.Run; 
end. 

    若是FastMM和FastMove同时使用的话,需要禁用其中一个条件编译,打开文件".../FastMM/FastMM4Options.inc",按Ctrl+F寻找字符串"$define UseCustomVariableSizeMoveRoutines",找到之后将此行改为如下:

{.$define UseCustomVariableSizeMoveRoutines} 

    使用FastMove代码可以使整个程序都使用到更快的内存移动函数而不仅仅是内存管理器。因此建议将FastMM和FastMove代码相结合,并关闭此选项。

FastMM、FastCode、FastMove打包下载:http://download.csdn.net/source/3337016

扩展资料:
1.Delphi中使用FastMM4结合View CPU避免内存泄漏 http://www.cnblogs.com/kongchao/archive/2009/10/27/1590479.html
2.FastMM使用详解 http://blog.csdn.net/shuaihj/archive/2011/03/17/6256723.aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
上次在盒子上用了可以加快Delphi2005速度的FastMM后,经试用,效果确实不错,于是我便在找一下FastMM在其它方面的应用。地址:http://sourceforge.net/projects/fastmm发现这个FastMM同样可以使Delphi以及用Delphi开发的程序变得更快(包括C++ Build 6)使用方法:解开FastMM427.zip,找到里面的FastMm427Replacement BorlndMM DLLPrecompiledfor Delphi IDEPerformance目录下的borlndMM.dll文件,把它复制到Delphi安装目录的bin中,把原文件覆盖即可。在应用程序中的使用,作者是这样说的:Using FastMM is very simple. All you have to do is add FastMM.pas as the very first unit in your project's .dpr file. Note that if you application uses .DLL files and you will be sharing memory (i.e. passing long strings or dynamic arrays between the DLL and main application), that you have to use FastMM in the DLL as well. If FastMM is not the first file in the "uses" section of the .dpr file, you will get an "invalid pointer operation" during program startup (meaning the default MM has already been used to allocate some memory). 意思是您只需要把FastMM4.pas加入到你的项目中,但要保证dpr文件uses后面第一个文件就是FastMM4.pas即可,经过本人实验,实际使用中还要加FastMM4Messages.pas或者设置一个搜索路径(设路径比较麻烦,还是加进来吧)。然后编译你的程序就可以了。如果你的dll用了共享内存,那么就用FastMM427Replacement BorlndMM DLLPrecompiledfor ApplicationsPerformance中的BorlndMM.dll和你的DLL文件一起分发即可。因为没看到盒子上有这方面的东西,因此就上传一个了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值