dmalloc 原文 翻译整理(1)

本文介绍了dmalloc库的快速使用方法,包括直接下载、编译和链接到程序。文章还强调了在ANSI C/C++系统中如何使用包含文件,并讨论了指针和size_t的类型要求。此外,详细讲解了内存对齐、最小分配开销等关键配置选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文版本 v2.8.4

 

L13 从快速入门开始(Quickstart)

 

这个库是一个文件中所有简化用法中最常见的:FTP下载它,编译它(-03),并连接到其他程序。全部编译时默认选择合理值在大多数平台。之后你也可以单步编译多次并动态调整选项。

 

This library is all in one file to simplify the most common usage:  ftp it, compile it (-O3), and link it into another program. All of  the compile-time options default to reasonable values for use on  most platforms.  You might later want to step through various  compile-time and dynamic tuning options.

 

L21 为了方便起见,一个包含文件为代码用于这个分配器在:ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.4.h 你并不是真的需要这个.h头文件除非你不调用在你的系统中定义的包含文件的的函数。这个.h头文件仅仅包含了使用这个分配器在ANSI c/c++系统所必须引用的文件。只要你不改变编译选项关于命名或者调整参数。如果你这么做了,你要创建你自己的malloc.h文件包含全部的设置,情况如下。注意你也许已经使用的c库默认包含一个分配器基于这个分配器的一个版本(比如linux)。您可能还需要使用在此文件中自定义设置,以避免与相关库版本之间的消费。

 

For convenience, an include file for code using this malloc is at:     ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.4.h  You don't really need this .h file unless you call functions not  defined in your system include files. The .h file contains only the  excerpts from this file needed for using this malloc on ANSI C/C++  systems, so long as you haven't changed compile-time options about  naming and tuning parameters.  If you do, then you can create your own malloc.h that does include all settings by cutting at the point indicated below. Note that you may already by default be using a C library containing a malloc that is based on some version of this  malloc (for example in linux). You might still want to use the one  in this file to customize settings or to avoid overheads associated with library versions.

 

L35 重要统计:

 

Vital statistics:

 

L37 支持指针/size_t代表:  4或8字节

      size_t必须必须是一个相同宽度无符号类型指针。(如果你使用的是一个老系统,声明size_t有符号类型或者需要一个不同宽度的指针,你可以用之前发布的这个分配器(2.72版本)。

 

Supported pointer/size_t representation:       4 or 8 bytes
size_t MUST be an unsigned type of the same width as pointers. (If you are using an ancient system that declares size_t as a signed type, or need it to be a different width than pointers, you can use a previous release of this malloc (e.g. 2.7.2) supporting these.)

 

L44 对齐 8字节(默认)这满足几乎现在所有的机器和C编译器。不过,你能定义MALLOC_ALIGNMENT去使它变宽如果必要的话(提高到128字节)以更多的空间为代价。

 

 Alignment:                                     8 bytes (default)
       This suffices for nearly all current machines and C compilers. However, you can define MALLOC_ALIGNMENT to be wider than this if necessary (up to 128bytes), at the expense of using more space.

 

L49 每块分配的最小开销: 4或8字节(如果尺寸为4字节)    8或16字节(如果尺寸为8字节)

每一个被分配的块有一个隐藏字开销支持尺寸、状态信息和校验字如果尾部定义。

 

  Minimum overhead per allocated chunk:   4 or  8 bytes (if 4byte sizes)
                                                         8 or 16 bytes (if 8byte sizes)
       Each malloced chunk has a hidden word of overhead holding size and status information, and additional cross-check word if FOOTERS is defined.

 

未完待续......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值