zoukankan      html  css  js  c++  java
  • [转] 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

  • 相关阅读:
    【常见Web应用安全问题】13、Blind SQL/XPath injection
    【常见Web应用安全问题】14、Google Hacking
    【常见Web应用安全问题】14、Google Hacking
    更新和插入新纪录
    Webservice调用方式:axis,soap详解
    Webservice:客户端用https
    hdu 1711(KMP入门题)
    poj 3349(hash判重)
    poj 2486(树形DP+背包)
    zoj 1588(桥)
  • 原文地址:https://www.cnblogs.com/rogge7/p/4601086.html
Copyright © 2011-2022 走看看