Delphi:你究竟有几个好妹妹(MM)
由于 Borland 为 Delphi 默认实现的内存管理器并不怎么给力(特别是多线程性能、跨模块不带包下共享等诸多限制),所以我很早就用开源的 FastMM作为其项目替代品。
http://sourceforge.net/projects/fastmm/
当初用 Delphi 7 时我甚至直接用 FastMM 把 RTL 的内存管理器实现代码也替掉了(一个 RTL 补丁)。而 Borland 在 Delphi 2006 后也直接内置了 FastMM 的一个版本作为内存管理器默认实现。FastMM 的内存泄露侦测功能非常牛 x,启用 FullDebugMode 配合一些其他的手段简直是消除内存泄露的杀手锏!(心得很多,有空再聊聊:)
不过 FastMM 在多核多线程应用中还是有不少限制,去年为了消除我们项目服务器代码中死锁的问题,也尝试了一些别的内存管理器,特别是这个 TopMM:
http://www.topsoftwaresite.nl/
相比 FastMM,TopMM 实现的比较顶层,也有一定的内存泄露报告功能,主要通过一套巧妙的方法实现更为高效的线程管理、内存分配(而不像 FastMM 的只有一个 Manager 大家“等”)其效果还是非常不错的(下面是官方的报告):
在多线程下的性能比较:
刚才在 Google 中无意发现这个 ScaleMM,看他的介绍和测评,貌似也很不错
http://code.google.com/p/scalemm/
It is faster (4x!) and scales better than FastMM. Also faster (3x) than TopMM, but equal scaling.
Because FastMM does not scale at all, you could use TopMM (which scales very good). But TopMM is slower than FastMM (in a simple string test).
I made a proof-of-concept to see if I could make a simple and very small and compact MM, which is not as bloated as FastMM and TopMM, so it is faster than these two. And of course it must scale on multi core CPU's.
这是官方的测评:
ScaleMM 的特点是适应性强,可以和 FastMM 协同,不过注意他的 readme 的说明:
= Limitations =
Currently only memory till 16384 bytes are handled by ScaleMM. Larger blocks
are handled by the previous memory manager.
Also there is no check for memory leaks. If you run it on top of FastMM (default
MM of Delphi 2007+), you will get memory leaks of ScaleMM itself.
由作者同时管理的如 asmprofiler 等项目看来,作者功底还是非常深厚的,不过 ScaleMM 这个项目非常年轻(Oct 13, 2010 才提交的 Google),当前项目中应用 ScaleMM 还是有风险,需要评估。
最后,现在是多核时代,内存管理器的性能提升往往能为程序执行的效率带来巨大的提升,Delphier 真的非常有“艳”福,有 FastMM、TopMM、ScaleMM、RecyclerMM、… 等开源的内存管理器,除此之外,还有 NexusDB Memory Manager 等商业的。
至于如何选择?这个也和谈恋爱差不多,经过比较、磨合,适合自己的就是最好的。 ;>



浙公网安备 33010602011771号