怎样安装使用fastmm?

本文详细介绍了如何在C++Builder 2009中安装并配置FastMM内存管理库来检测内存泄漏。包括下载FastMM,将所需文件复制到项目目录,调整编译设置,以及启用全调试模式的方法。

怎样安装使用fastmm?一篇英文说得很清楚。

 

Had to go to FastMM page to get FastMM4: http://sourceforge.net/projects/fastmm/

Copy FastMM4BCB.cpp, FastMM4.pas, FastMM4Message.pas, and FastMM4Options.inc to your project directory.

Add FastMM4Messages.pas first, then FastMM4.pas, then FastMM4BCB.cpp. On compiling the .pas files, .hpp files are created and imported by the subsequent files.

Then, you must add USEOBJ("FastMM4BCB.cpp") to your project file, BEFORE any other USEFORM directives. This apparently is the (completely undocumented) equivalent to the "uses" directive in Delphi.

Before compiling, you must add the following line at the beginning of FastMM4BCB.cpp, so that the _TEXT("string") macros used in that .cpp (but not defined in that file) work as intended:

if you are using UNICODE (Project/Options/Directories and Conditionals/TCHAR maps to wchar_t):
#define _TEXT(a) L##a

if you are not using UNICODE (Project/Options/Directories and Conditionals/TCHAR maps to char)
#define _TEXT(a) a

Finally, as per the instructions in FastMM4BCB.cpp, you must set Project/Options/C++ Linker/Dynamic RTL to False.

If you either fail to set Dynamic RTL to false or use the USEOBJ directive, you will get the infamous:
FastMM4 cannot be installed since another third party memory manager has already installed itself.
If you want to use FastMM4, please make sure that FastMM4.pas is the very first unit in the "uses"
section of your project's .dpr file.

You can now compile and run your program with FastMM4. You will find some memory leaks in Embarcadero's code, as indicated in the message box
shown when your application terminates.

As suggested in the message box, you can enable FullDebugMode by removing the "." in {.FullDebugMode} in FastMM4Options.inc. However, then FastMM4.pas does not compile, with
an error at line 1351 in the definition of StandardVirtualMethodNames. Googling that does not give any clue as to how to fix that problem.
So, does anyone know how to enable FastMM4 FullDebugMode in C++ Builder 2009 so we can get the leak reporting mentioned above?


Thus, the full set of instructions for getting memory leak detection working under C++ Builder 2009:

Go to FastMM page to get FastMM4: http://sourceforge.net/projects/fastmm/

Copy FastMM4BCB.cpp, FastMM4.pas, FastMM4Message.pas, FastMM4Options.inc, and FastMM_FullDebugMode.lib to your project directory.

Copy FastMM_FullDebugMode.dll to your application's .exe's directory

To your project, add FastMM4Messages.pas first, then FastMM4.pas, then FastMM4BCB.cpp to the project. On compiling the .pas files, .hpp files are created and imported by the subsequent files.

Then, you must add USEOBJ("FastMM4BCB.cpp") to your project file, BEFORE any other USEFORM directives. This apparently is the (completely undocumented) equivalent to the "uses" directive in Delphi.

Before compiling, you must add the following line at the beginning of FastMM4BCB.cpp, so that the _TEXT("string") macros used in that .cpp (but not defined in that file) work as intended:
#include <tchar.h>

Before compiling, you must comment out the check for the Delphi version (since you are not compiling with Delphi). Find the line
{$ifdef Delphi6AndUp} at about line 1337 and the matching {$endif} at about line 1343 (NOT the {$ifend} that matches {$if RTLVersion >= 20}) and comment both of those lines by adding a period:
{.$ifdef Delphi6AndUp}
{.$endif}

Finally, as per the instructions in FastMM4BCB.cpp, you must set Project/Options/C++ Linker/Dynamic RTL to False.

If you either fail to set Dynamic RTL to false or to use the USEOBJ directive, you will get the infamous:
FastMM4 cannot be installed since another third party memory manager has already installed itself.
If you want to use FastMM4, please make sure that FastMM4.pas is the very first unit in the "uses"
section of your project's .dpr file.

You can now compile and run your program with FastMM4. You will find some memory leaks in Embarcadero's code, as indicated in the message box
shown when your application terminates.

As suggested in that message box, you can enable FullDebugMode by removing the "." in {.FullDebugMode} in FastMM4Options.inc to get a text file that reports the leaks in detail
No, the Embcarcadero version has Pierre postings as of 5/23/2009.
I was suggesting you ask there as that is where he tends to hang out.
Other fastcode programmers and FastMM users also monitor the group.

Thank you for pointing me to the newsgroup. For others, this is a newsgroup on newsgroups.codegear.com with the full name embarcadero.public.delphi.language.basm

上次在盒子上用了可以加快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、付费专栏及课程。

余额充值