A Memory Allocator
by Doug Lea
（其它同文译作：http://article.yeeyan.org/view/25646/6380?from_com，译者 Firefly Huang）
[A German adaptation and translation of this article appears in unix/mail December, 1996. This article is now out of date, and doesn't reflect details of current version of malloc.]
Memory allocators form interesting case studies in the engineering of infrastructure software. I started writing one in 1987, and have maintained and evolved it (with the help of many volunteer contributors) ever since. This allocator provides implementations of the the standard C routines malloc(), free(), and realloc(), as well as a few auxiliary utility routines. The allocator has never been given a specific name. Most people just call it Doug Lea's Malloc, or dlmalloc for short.
（内存分配器是极佳的基础软件工程学研究素材。1987年我撰写了一个内存分配器并一直持续地维护和改进（其间得到不少同好大力帮助）。本分配器实现了标准C例程malloc()、free() 、realloc()以及少量辅助例程。从来没人给这个东东起过特别炫目的名字，大多数人称之为“Doug Lea's Malloc”，或干脆简称为“dlmalloc”。）
The code for this allocator has been placed in the public domain (available from ftp://g.oswego.edu/pub/misc/malloc.c), and is apparently widely used: It serves as the default native version of malloc in some versions of Linux; it is compiled into several commonly available software packages (overriding the native malloc), and has been used in various PC environments as well as in embedded systems, and surely many other places I don't even know about.
I wrote the first version of the allocator after writing some C++ programs that almost exclusively relied on allocating dynamic memory. I found that they ran much more slowly and/or with much more total memory consumption than I expected them to. This was due to characteristics of the memory allocators on the systems I was running on (mainly the then-current versions of SunOs and BSD ). To counter this, at first I wrote a number of special-purpose allocators in C++, normally by overloading operator new for various classes. Some of these are described in a paper on C++ allocation techniques that was adapted into the 1989 C++ Report article Some storage allocation techniques for container classes.
（在编写了数个极其依赖动态内存分配的C++程序后，我构造了这个玩意儿的第一个实现版本——因为我发现，那些C++程序比预想中慢，同时（或有时）消耗更多的内存——这得归因于当时使用的操作系统（主要是SunOS和BSD的早期版本）自带的内存分配器的技术特性。通过在C++中简单地为有特殊需求的类重载new操作符（operator new），我尝试着实现特定用途的内存分配器以解决这一问题。其中一部分实现被记载入一份有关 C++ 内存分配技术的论文中，后于1989年以《Some storage allocation techniques for container classes》为题刊载在《C++ Report》上。）
However, I soon realized that building a special allocator for each new class that tended to be dynamically allocated and heavily used was not a good strategy when building kinds of general-purpose programming support classes I was writing at the time. (From 1986 to 1991, I was the the primary author of libg++ , the GNU C++ library.) A broader solution was needed -- to write an allocator that was good enough under normal C++ and C loads so that programmers would not be tempted to write special-purpose allocators except under very special conditions.
（那时，在实现部分通用编程支撑类（general-purpose programming support classes）后，我随即意识到，为每一类依赖动态分配和频繁取用的对象编写特定内存分配器是十分不智的（1986年至1991年间我是GNU C++类库libg++的主要作者）。实现更通用的解决方案——即编写一个在常见C/C++工作负载下表现得足够好的内存分配器，以求将陷于重复发明特定用途轮子之泥沼中的程序员们解救出来——是十分必要的，除非他们正与非常非常特殊的需求作斗争。）
This article presents a description of some of the main design goals, algorithms, and implementation considerations for this allocator. More detailed documentation can be found with the code distribution.