⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmalloc.texi

📁 减少内存碎片的malloc分配函数
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
\input texinfo @c -*-texinfo-*-@c %**start of header@setfilename dmalloc.info@settitle Dmalloc Tutorial@setchapternewpage odd@headings double@c %**end of header  @dircategory Libraries@direntry* Dmalloc: (dmalloc).			Malloc debug library.@end direntry@c ----------------------------------------------------------------@c $Id: dmalloc.texi,v 1.267 2004/10/19 14:50:52 gray Exp $@c ----------------------------------------------------------------@c ----------------------------------------------------------------@set dmalloc_version Version 5.4.2@set dmalloc_date October 2004@set dmalloc_copyright Copyright 1992 to 2004 by Gray Watson.@c ----------------------------------------------------------------@ifinfoThis file is an introduction to the Dmalloc library which handles generalmemory heap management.@value{dmalloc_copyright}Permission is granted to make and distribute verbatim copies of thismanual provided the copyright notice and this permission notice arepreserved on all copies.@ignorePermission is granted to process this file through TeX and print theresults, provided the printed document carries a copying permissionnotice identical to this one except for the removal of this paragraph(this paragraph not being relevant to the printed manual).@end ignorePermission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also that thechapter entitled ``Copying'' are included exactly as in the original,and provided that the entire resulting derived work is distributed underthe terms of a permission notice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that the chapter entitled ``Copying'' may be included in atranslation approved by the author instead of in the original English.@end ifinfo@titlepage@title Debug Malloc Library@subtitle @value{dmalloc_version}@subtitle @value{dmalloc_date}@author Gray Watson@page@value{dmalloc_copyright}Published by Gray WatsonPermission is granted to make and distribute verbatim copies of thismanual provided the copyright notice and this permission notice arepreserved on all copies.Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also that thechapter entitled ``Copying'' are included exactly as in the original,and provided that the entire resulting derived work is distributed underthe terms of a permission notice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that the chapter entitled ``Copying'' may be included in atranslation approved by the author instead of in the original English.@end titlepage@c --------------------------------@node Top, Copying, (dir), (dir)@top Debug Malloc Library@ifinfo@value{dmalloc_version} -- @value{dmalloc_date}@end ifinfo@cindex introduction@cindex authorThe debug memory allocation or @dfn{dmalloc} library has been designedas a drop in replacement for the system's @code{malloc}, @code{realloc},@code{calloc}, @code{free} and other memory management routines whileproviding powerful debugging facilities configurable at runtime.  Thesefacilities include such things as memory-leak tracking, fence-post writedetection, file/line number reporting, and general logging ofstatistics.The library is reasonably portable having been run successfully on atleast the following operating systems: AIX, DGUX, Free/Net/OpenBSD,GNU/Hurd, HPUX, Irix, Linux, Mac OSX, NeXT, OSF/DUX, SCO, Solaris,Ultrix, Unixware, MS Windows, and Unicos on a Cray T3E.  It alsoprovides support for the debugging of threaded programs.  @xref{UsingWith Threads}.The package includes the library, configuration scripts, debug utilityapplication, test program, and documentation.  Online documentation aswell as the full source is available at URL @uref{http://dmalloc.com/}.Details on the library's mailing list are available there as well.Please use the forums at URL @uref{http://dmalloc.com/forums/} todiscuss any problems or to request features.  If you are still havingproblems, the author can be reached via his home page at URL@uref{http://256.com/gray/} with questions or feedback.  Please includethe version number of the library that you are using, your machine andoperating system types, and the value of the DMALLOC_OPTIONS environmentvariable.Gray Watson.@menu* Copying::                     Library copying and licensing conditions.* Overview::                    Description of features and how to get started.* Programming::                 How to program with the library.* Dmalloc Program::             How to use the library's utility.* Source Code::                 Information on the source code.* Troubleshooting::             Some solutions to common problems.* Index of Concepts::           Index of concepts in the manual.@end menu@c ----------------------------------------------------------------------------@node Copying, Overview, Top, Top@chapter Library Copying and Licensing Conditions@cindex copying@cindex license@cindex library permissions@cindex permissions of the library@value{dmalloc_copyright}Permission to use, copy, modify, and distribute this software for anypurpose and without fee is hereby granted, provided that the abovecopyright notice and this permission notice appear in all copies, andthat the name of Gray Watson not be used in advertising or publicitypertaining to distribution of the document or software without specific,written prior permission.Gray Watson makes no representations about the suitability of thesoftware described herein for any purpose.  It is provided ``as is''without express or implied warranty.@c ----------------------------------------------------------------------------@node Overview, Programming, Copying, Top@chapter Description of Features and How to Get Started@cindex overview@menu* Installation::                How to install the library.* Getting Started::             Getting started with the library.* Allocation Basics::           Basic description of terms and functions.* Features::                    General features of the library.* How It Works::                How the library checks your program.@end menu@c --------------------------------@node Installation, Getting Started, Overview, Overview@section How to Install the Library@cindex installing the library@cindex compiling the library@cindex building the library@cindex configuring the library@cindex making the libraryTo configure, compile, and install the library, follow these stepscarefully.@enumerate@item Make sure you have the latest version of the library availablefrom the home page at URL @uref{http://dmalloc.com/}.@cindex settings.dist file@item You may want to edit or at least review the settings in@file{settings.dist} to tune specific features of the library.  The@file{configure} script will copy this file to @file{settings.h} whichis where you should be adding per-architecture settings.@cindex configure script@cindex --disable-cxx@cindex --enable-threads@cindex --enable-shlib@cindex conf.h file@item Type @kbd{sh ./configure} to configure the library.  You may wantto first examine the @file{config.help} file for some information aboutconfigure.  You may want to use the @kbd{--disable-cxx} option if you donot want the Makefile to build the C++ version of dmalloc.  You may wantto use the @kbd{--enable-threads} option to build the threaded versionof dmalloc.  You may want to use the @kbd{--enable-shlib} option tobuild the shared versions of the dmalloc libraries.  @kbd{sh ./configure--help} lists the available options to configure.  Configure shouldgenerate the @file{Makefile} and configuration files automatically.@item You may want to examine the @file{Makefile} and @file{conf.h} filescreated by configure to make sure it did its job correctly.@cindex settings.h file@item You might want to tune the settings in @file{settings.h} file totune the library to the local architecture.  This file contains relevantsettings if you are using pthreads or another thread library.@xref{Using With Threads}.  The @file{configure} script created thisfile from the @file{settings.dist} file.  Any permanent changes to thesesettings should made to the @file{settings.dist} file.  You then can run@file{config.status} to re-create the @file{settings.h} file.@cindex DMALLOC_SIZE variable@item The @code{DMALLOC_SIZE} variable gets auto-configured in@file{dmalloc.h.2} but it may not generate correct settings for allsystems.  You may have to alter the definitions in this file to getthings to stop complaining when you go to compile about the sizearguments to malloc routines.  Comments on this please.@item Typing @kbd{make} should be enough to build @file{libdmalloc.a},and @file{dmalloc} program.  If it does not work, please see if thereare any notes in the contrib directory about your system-type.  If notand you figure your problem out, please send me some notes so futureusers can profit from your experiences.@emph{NOTE}: You may experience some errors compiling some of thereturn.h assembly macros which attempt to determine the callers addressfor logging purposes.  You may want to first try disabling any compileroptimization flags.  If this doesn't work then you may need to disablethe @samp{USE_RETURN_MACROS} variable in the @file{settings.h} file.@cindex ANSI-C compiler@emph{NOTE}: The code is dependent on an ANSI-C compiler.  If theconfigure script gives the @samp{WARNING} that you do not have an ANSI-Ccompiler, you may still be able to add some sort of option to yourcompiler to make it ANSI.  If there such is an option, please send it tothe author so it can be added to the configure script.@item If you use threads and did not add the @kbd{--enable-threads}argument to configure, typing @kbd{make threads} should be enough tobuild @file{libdmallocth.a} which is the threaded version of thelibrary.  This may or may not work depending on the configurationscripts ability to detect your local thread functionality.  Feel free tosend me mail with improvements.See the ``Using With Threads'' section for more information about theoperation of the library with your threaded program.  @xref{Using WithThreads}.@item If you have a C++ compiler installed, the library should haveautomatically built @file{libdmallocxx.a} which is the C++ version ofthe library.  If it was not done automatically, you can build it bytyping @kbd{make cxx}.  You should link this library into your C++programs instead of @file{libdmalloc.a}.  See the @file{dmallocc.cc} C++file which contains basic code to overload the @code{new}, @code{new[]},@code{delete}, and @code{delete[]} C++ operators.  My apologies on theminimal C++ support.  I am still living in a mostly C world.  Any helpimproving this interface without sacrificing portability would beappreciated.@cindex testing the library@cindex dmalloc_t test program@item Typing @kbd{make light} should build and run the @file{dmalloc_t} testprogram through a set of light trials.  By default this will execute@file{dmalloc_t} 5 times -- each time will execute 10,000 mallocoperations in a very random manner.  Anal folks can type @kbd{makeheavy} to up the ante.  Use @kbd{dmalloc_t --usage} for the list of all@file{dmalloc_t} options.@item Typing @kbd{make install} should install the @file{libdmalloc.a}library in @file{/usr/local/lib}, the @file{dmalloc.h} include file in@file{/usr/local/include}, and the @file{dmalloc} utility in@file{/usr/local/bin}.  You may also want to type @kbd{make installth}to install the thread library into place and/or @kbd{make installcc} toinstall the C++ library into place.You may have specified a @samp{--prefix=PATH} option to configure inwhich case @samp{/usr/local} will have been replaced with @samp{PATH}.@end enumerateSee the ``Getting Started'' section to get up and running with thelibrary.  @xref{Getting Started}.@c --------------------------------@node Getting Started, Allocation Basics, Installation, Overview@section Getting Started with the Library@cindex quick start@cindex getting started@cindex jump start@cindex how to begin@cindex where to begin@cindex beginningThis section should give you a quick idea on how to get going.Basically, you need to do the following things to make use of thelibrary:@enumerate@item Make sure you have the latest version of the library availablefrom the home page at URL @uref{http://dmalloc.com/}.@item Follow the installation instructions on how to configure,make, and install the library (i.e. type: @kbd{make install}).@xref{Installation}.@cindex automatic shutdown@cindex shutdown, automatic@cindex on_exit@cindex atexit@cindex destructor@item You need to make sure that the library configuration andbuild process above was able to locate one of the @code{on_exit}function, @code{atexit} function, or had compiler destructor support.If one of these functions or support is available then the dmalloclibrary should be able to automatically shut itself down when theprogram exits.  This causes the memory statistics and unfreedinformation to be dumped to the log file.  However, if your system hasnone of the above, then you will need to call @code{dmalloc_shutdown}yourself before your program exits.@cindex alias, shell@cindex bash shell@cindex ksh shell@cindex zsh shell@item Add an alias for dmalloc to your shell's rc file if supported.The idea is to have the shell capture the dmalloc program's output andadjust the environment.  Bash, ksh, and zsh users should add thefollowing to their @file{.bashrc}, @file{.profile}, or @file{.zshrc}file respectively (notice the @kbd{-b} option for bourne shell output):@examplefunction dmalloc @{ eval `command dmalloc -b $*`; @}@end exampleIf your shell does not support the @code{command} function then try:@examplefunction dmalloc @{ eval `\dmalloc -b $*`; @}@end exampleor@examplefunction dmalloc @{ eval `/usr/local/bin/dmalloc -b $*`; @}@end example@cindex csh shell@cindex tcsh shellIf you are @emph{still} using csh or tcsh, you should add the followingto your @file{.cshrc} file (notice the @kbd{-C} option for c-shelloutput):

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -