Books : Mastering Borland Delphi 2005: Update for Delphi 2006

Mastering Delphi Update for Delphi 2006

Chapter 5

Delphi 2006 Win32 Run Time Library

In Delphi 2006 there are several interesting new features in the Win32 Run Time Library (RTL). The most relevant is with no doubt the introduction of a new memory manager, FastMM. This new memory manager is used by the IDE itself and is now also the default memory manager for the Delphi compiler applications. When you reopen an existing Delphi project in Delphi 2006 and recompile it you'll automatically have the new memory manager in action (unless you previously replaced the standard memory manager with a custom one in the project).

Beside the new memory manager, there are also many optimized RTL functions, some of which are coming from the FastCode project, while others relate to unit checks made on package loading.


The new memory managed is called FastMM4 and has been developed as an open source project mainly by Pierre La Riche, a Delphi programmer from South Africa. FastMM4 optimizes the allocation of memory, speeding it up and freeing more RAM for subsequent use (the traditional Delphi memory manager suffered from excessive memory fragmentation). This is even more true for multi-threaded applications. FastMM is also capable of doing more extensive memory checks on the effective memory clean-up, on the wrongful use of deleted objects, including interface based access to that data, on memory overwrites and on buffer overruns. It can also provide some feedback on the left-over objects, helping you track memory leaks.

Actually some of the more advanced features of FastMM are available in the full version of the library, not in the one that has been added to the Delphi RTL, which used the same engine but without some of the more advanced checks. This way Delphi ensures a better compatibility with existing applications and avoids adding powerful features that not all programmers will be able to master easily. In fact, when you enable all of the debug options of the full memory manager you might end up seeing errors that didn't show up with the traditional memory manager, including some double deletions, overruns, and too-late interface method calls.

As I mentioned, to use the new memory manager you don't have to do anything: Open a project in Delphi 2006 and recompile it. If you want to have the capabilities of the full version, though, you have to download its source code from:


FastMM4 has been picked by Borland for its technical qualities, but also because it resulted as the winner of the memory tests of the FastCode project. This is a group of Delphi programmers that define some tests suites for different function calls part of the RTL, trying to come up with the most optimized version. In some cases the implementation is written in Pascal, but in many others this is low-level assembly code.

As described in the section “FastCode in Delphi 2005” (page 157) of the printed book, some of these routines were already part of Delphi 2005. The RTL of Delphi 2006 adds many more, some of which are very significant as they are commonly used:

Other New RTL Features

Among the other features of the runtime library, there is a change in the checks for duplicated units that takes place when you load packages dynamically (not just in the IDE, but also in your own applications). In the past this was based on a linear search in a list, now it uses a hash table. You can even disable this check altogether for your own projects, but only do so if you are sure there are no duplicated unit names among different packages you load. This is mainly an IDE optimization shaving a lot of time out of the IDE startup.

Some of the classic RTL classes have new properties and some units have additional functions, including the following: