6

As an exercise I am writing a memory manager - that is, the code which implements malloc, realloc and free (or new and delete.) The RTL for my language, Delphi, allows the RTL's memory manager to be replaced easily. For those of you using C++, this is similar to, but lower-level than, overriding new and delete (it hooks into the RTL itself rather than being a language feature.) I'm looking for resources about high-quality approaches others have taken to the same problem.

I'm aware of a couple of memory management algorithms and implementations, including FastMM4 (quite complex), Doug Lea's allocator, Buddy, JeMalloc, TcMalloc, and Hoard. I am searching for information about the following:

  • Known, recommended algorithms: what other high-quality algorithms than the above have been published?

  • Are there specific algorithms tailored for highly threaded applications? That is, where there may be high thread contention at any locked points for allocation or freeing, and where memory may be allocated in one thread but deallocated in a different thread? Most algorithms - with the notable exceptions of Hoard, JeMalloc and TcMalloc - seem to be designed for single-threaded work, and the thread awareness is only thread safety in that there are locks or other synchronisation at appropriate points - no special design.

  • What do major vendors use? While Delphi and C++ Builder's is documented, I cannot find any information about the implementations used by MS VC++, .Net, or Objective C. (All documentation seems to be higher-level, such as NSAutoReleasePool for example. Linux seems to use Buddy.) These vendors do not seem to allow their RTL to be hooked into like Delphi does. I would be very interested to read about their implementations.

4

0 回答 0