zoukankan      html  css  js  c++  java
  • FastMM、FastCode、FastMove的使用(图文并茂)

        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

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

  • 相关阅读:
    Unity The Method Signature Matching Rule
    Unity The Property Matching Rule
    Unity The Type Matching Rule
    Unity The Custom Attribute Matching Rule
    Unity The Member Name Matching Rule
    Unity No Policies
    Unity The Return Type Matching Rule
    Unity The Parameter Type Matching Rule
    Unity The Namespace Matching Rule
    关于TSQL递归查询的(转)
  • 原文地址:https://www.cnblogs.com/findumars/p/6181749.html
Copyright © 2011-2022 走看看