[译][内存分配]A Memory Allocator(内存分配器)(简介部分)

BluntBlade 2010-02-24 06:28:25
以下文字纯属蛋疼,若有雷同……欢迎来函来电来稿来邮。

[译]
[内存分配]
A Memory Allocator
(内存分配器)

by Doug Lea
(作者: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.]
([待译])

Introduction
(简介)

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.
(任何人都可以从ftp://g.oswego.edu/pub/misc/malloc.c自由取用本分配器的源代码,显然它得到了广泛的应用:被某些Linux版本用作默认的原生malloc;编译进常见软件包(取代平台的原生malloc);以及用于PC和嵌入式环境中。当然还有更多我从未听说过的应用。)

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.
(本文记述该内存分配器的主要设计目标、算法及实现手法考量。更多详细内容请参见源代码。)
...全文
154 点赞 收藏 8
写回复
8 条回复
昵称很不好取 2010年03月10日
回复 点赞
macrojj 2010年03月10日
Mark。。。。。太短
回复 点赞
r11222 2010年02月26日
收藏了,不容易啊
回复内容 回复内容太短了!
回复 点赞
BluntBlade 2010年02月25日
因为我发现,那些C++程序比预期的要慢,同时(或有时)消耗预期外的更多内存

除非他们正在非常非常特殊的场合与设计指标作斗争。

PS:
本译稿第一优先更新地址为http://www.douban.com/group/topic/10018554/
回复 点赞
pengzhixi 2010年02月25日
收藏了,不容易啊
回复内容 回复内容太短了!
回复 点赞
lin_style 2010年02月25日
不容易。。顶一下。。希望LZ不要太紧。
回复 点赞
Wolf0403 2010年02月25日
同时(或有时)消耗更多的内存
同时(或有时)消耗比预期更多的内存

正与非常非常特殊的需求作斗争。)
- “需求”是特殊名词吧?用“情况”?

回复 点赞
yshuise 2010年02月25日
d
回复内容太短了!
回复内容太短了!
回复 点赞
发动态
发帖子
非技术区
创建于2007-09-28

4415

社区成员

5.8w+

社区内容

C/C++ 非技术区
社区公告
暂无公告