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

📄 a garbage collector for c and c++.mht

📁 gc6.7 一个适用于CC++的内存垃圾回收器,可以像Java中那样随意的分配内存而不用释放,也不必担心内存泄漏了
💻 MHT
📖 第 1 页 / 共 4 页
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: A garbage collector for C and C++
Date: Sun, 26 Nov 2006 22:51:08 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
	boundary="----=_NextPart_000_004A_01C711AD.5CD250D0";
	type="text/html"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807

This is a multi-part message in MIME format.

------=_NextPart_000_004A_01C711AD.5CD250D0
Content-Type: text/html;
	charset="gb2312"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.hpl.hp.com/personal/Hans_Boehm/gc/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" =
"http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML><HEAD><TITLE>A garbage collector for C and C++</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.2800.1578" name=3DGENERATOR></HEAD>
<BODY>
<TABLE cellPadding=3D10 bgColor=3D#f0f0ff>
  <TBODY>
  <TR>
    <TD><A=20
      =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcinterface.html">In=
terface=20
      Overview</A></TD>
    <TD><A=20
      =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/04tutorial.pdf">Tuto=
rial=20
      Slides</A></TD>
    <TD><A=20
    =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/faq.html">FAQ</A></T=
D>
    <TD><A=20
      =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/simple_example.html"=
>Example</A></TD>
    <TD><A=20
      =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source">Download<=
/A></TD>
    <TD><A=20
      =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/license.txt">License=
</A></TD></TR></TBODY></TABLE>
<H1>A garbage collector for C and C++</H1>
<UL>
  <LI><A =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#where">Where to =
get=20
  the collector</A>=20
  <LI><A=20
  =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#platforms">Platform=
s</A>=20
  <LI><A=20
  =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#multiprocessors">Sc=
alable=20
  multiprocessor versions</A>=20
  <LI><A =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#details">Some=20
  collector details</A>=20
  <LI><A =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#further">Further=20
  reading</A>=20
  <LI><A =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#users">Current=20
  users</A>=20
  <LI><A =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#collector">Local=20
  Links for this collector</A>=20
  <LI><A =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#background">Local=20
  Background Links</A>=20
  <LI><A =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/#contacts">Contacts =

  and Mailing List</A> </LI></UL>[ This is an updated version of the =
page formerly=20
at <TT>http://reality.sgi.com/boehm/gc.html</TT> and before that at <A=20
href=3D"ftp://parcftp.xerox.com/pub/gc/gc.html"><TT>ftp://parcftp.xerox.c=
om/pub/gc/gc.html</TT></A>.]=20

<P>The <A =
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm">Boehm</A>-<A=20
href=3D"http://www.cs.cornell.edu/annual_report/00-01/bios.htm#demers">De=
mers</A>-<A=20
href=3D"http://www-sul.stanford.edu/weiser/">Weiser</A> conservative =
garbage=20
collector can be used as a garbage collecting replacement for C =
<TT>malloc</TT>=20
or C++ <TT>new</TT>. It allows you to allocate memory basically as you =
normally=20
would, without explicitly deallocating memory that is no longer useful. =
The=20
collector automatically recycles memory when it determines that it can =
no longer=20
be otherwise accessed. A simple example of such a use is given <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/simple_example.html"=
>here</A>.=20

<P>The collector is also used by a number of programming language=20
implementations that either use C as intermediate code, want to =
facilitate=20
easier interoperation with C libraries, or just prefer the simple =
collector=20
interface. For a more detailed description of the interface, see <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcinterface.html">he=
re</A>.=20
<P>Alternatively, the garbage collector may be used as a <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/leak.html">leak =
detector</A>=20
for C or C++ programs, though that is not its primary goal.=20
<P>The arguments for and against conservative garbage collection in C =
and C++=20
are briefly discussed in <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/issues.html">issues.=
html</A>.=20
The beginnings of a frequently-asked-questions list are <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/faq.html">here</A>. =

<P>Empirically, this collector works with most unmodified C programs, =
simply by=20
replacing <TT>malloc</TT> with <TT>GC_malloc</TT> calls, replacing=20
<TT>realloc</TT> with <TT>GC_realloc</TT> calls, and removing free =
calls.=20
Exceptions are discussed in <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/issues.html">issues.=
html</A>.=20

<H2><A name=3Dwhere>Where to get the collector</A></H2>
<P>Typically several versions will be available. Usually you should =
first try to=20
use <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc.tar.gz"=
><TT>gc_source/gc.tar.gz</TT></A>,=20
which is normally an older, more stable version.=20
<P>If that fails, try the latest explicitly numbered version in <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/"><TT>gc_s=
ource/</TT></A>.=20
Later versions may contain additional features, platform support, or bug =
fixes,=20
but are likely to be less well tested. Note that versions containing the =
letters=20
<TT>alpha</TT> are even less well tested than others, especially on =
non-HP=20
platforms.=20
<P>The latest experimental version of the source code is now maintained =
on the=20
SourceForge site (project "bdwgc"). It can be browsed <A=20
href=3D"http://bdwgc.cvs.sourceforge.net/bdwgc/">here</A>.=20
<P>To anonymously check out a CVS version use: <BR><TT>cvs=20
-d:pserver:anonymous@bdwgc.cvs.sourceforge.net:/cvsroot/bdwgc login =
<BR>cvs -z3=20
-d:pserver:anonymous@bdwgc.cvs.sourceforge.net:/cvsroot/bdwgc co -P =
bdwgc</TT>=20
<P>Maintainers can check out a version for development with <BR><TT>cvs =
-z3=20
-d:ext:&lt;name&gt;@bdwgc.cvs.sourceforge.net:/cvsroot/bdwgc co -P =
bdwgc</TT>=20
<BR>with <TT>CVS_RSH</TT> set to </TT>ssh</TT>, or whatever is needed to =
satisfy=20
your firewall.=20
<P>A slightly older version of the garbage collector is now also =
included as=20
part of the <A href=3D"http://gcc.gnu.org/">GNU compiler</A> =
distribution. The=20
source code for that version is available for browsing <A=20
href=3D"http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/boehm-gc/">here</A>.=20
<P>The garbage collector code is copyrighted by <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm">Hans-J. Boehm</A>, =
Alan J.=20
Demers, <A href=3D"http://www.xerox.com/">Xerox Corporation</A>, <A=20
href=3D"http://www.sgi.com/">Silicon Graphics</A>, and <A=20
href=3D"http://www.hp.com/">Hewlett-Packard Company</A>. It may be used =
and copied=20
without payment of a fee under minimal restrictions. See the README file =
in the=20
distribution or the <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/license.txt">license=
</A> for=20
more details. <B>IT IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY =
EXPRESSED OR=20
IMPLIED. ANY USE IS AT YOUR OWN RISK</B>.=20
<H2><A name=3Dplatforms>Platforms</A></H2>The collector is not =
completely=20
portable, but the distribution includes ports to most standard PC and =
UNIX/Linux=20
platforms. The collector should work on Linux, *BSD, recent Windows =
versions,=20
MacOS X, HP/UX, Solaris, Tru64, Irix and a few other operating systems. =
Some=20
ports are more polished than others. There are <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/porting.html">instru=
ctions</A>=20
for porting the collector to a new platform.=20
<P>Irix pthreads, Linux threads, Win32 threads, Solaris threads (old =
style and=20
pthreads), HP/UX 11 pthreads, Tru64 pthreads, and MacOS X threads are =
supported=20
in recent versions.=20
<H3>Separately distributed ports</H3>For MacOS 9/Classic use, Patrick =
Beard's=20
latest port is available from <A=20
href=3D"http://homepage.mac.com/pcbeard/gc/"><TT>http://homepage.mac.com/=
pcbeard/gc/</TT></A>.=20
(Unfortunately, that's now quite dated. I'm not in a position to test =
under=20
MacOS. Although I try to incorporate changes, it is impossible for me to =
update=20
the project file.)=20
<P>Precompiled versions of the collector for NetBSD are available <A=20
href=3D"ftp://ftp.netbsd.org/pub/NetBSD/packages/pkgsrc/devel/boehm-gc/RE=
ADME.html">here</A>=20
or <A =
href=3D"http://www.netbsd.org/packages/devel/boehm-gc/README.html">here</=
A>.=20

<P><A href=3D"http://www.debian.org/">Debian Linux</A> includes =
prepackaged=20
versions of the collector.=20
<H2><A name=3Dmultiprocessors>Scalable multiprocessor =
versions</A></H2>Kenjiro=20
Taura, Toshio Endo, and Akinori Yonezawa have made available a <A=20
href=3D"http://www.yl.is.s.u-tokyo.ac.jp/gc/">parallel collector</A> =
based on this=20
one. Their collector takes advantage of multiple processors during a =
collection.=20
Starting with collector version 6.0alpha1 we also do this, though with =
more=20
modest processor scalability goals. Our approach is discussed briefly in =
<A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/scale.html"><TT>scal=
e.html</TT></A>.=20

<H2><A name=3Ddetails>Some Collector Details</A></H2>The collector uses =
a <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/complexity.html">mar=
k-sweep</A>=20
algorithm. It provides incremental and generational collection under =
operating=20
systems which provide the right kind of virtual memory support. =
(Currently this=20
includes SunOS[45], IRIX, OSF/1, Linux, and Windows, with varying =
restrictions.)=20
It allows <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/finalization.html"><=
I>finalization</I></A>=20
code to be invoked when an object is collected. It can take advantage of =
type=20
information to locate pointers if such information is provided, but it =
is=20
usually used without such information. ee the README and <TT>gc.h</TT> =
files in=20
the distribution for more details.=20
<P>For an overview of the implementation, see <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcdescr.html">here</=
A>.=20
<P>The garbage collector distribution includes a C string (<A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/cordh.txt"=
><I>cord</I></A>)=20
package that provides for fast concatenation and substring operations on =
long=20
strings. A simple curses- and win32-based editor that represents the =
entire file=20
as a cord is included as a sample application.=20
<P>Performance of the nonincremental collector is typically competitive =
with=20
malloc/free implementations. Both space and time overhead are likely to =
be only=20
slightly higher for programs written for malloc/free (see Detlefs, =
Dosser and=20
Zorn's <A=20
href=3D"ftp://ftp.cs.colorado.edu/pub/techreports/zorn/CU-CS-665-93.ps.Z"=
>Memory=20
Allocation Costs in Large C and C++ Programs</A>.) For programs =
allocating=20
primarily very small objects, the collector may be faster; for programs=20
allocating primarily large objects it will be slower. If the collector =
is used=20
in a multithreaded environment and configured for thread-local =
allocation, it=20
may in some cases significantly outperform malloc/free allocation in =
time.=20
<P>We also expect that in many cases any additional overhead will be =
more than=20
compensated for by decreased copying etc. if programs are written and =
tuned for=20
garbage collection.=20
<H1><A name=3Dfurther>Further Reading:</A></H1><B>The beginnings of a =
frequently=20
asked questions list for this collector are <A=20
href=3D"http://www.hpl.hp.com/personal/Hans_Boehm/gc/faq.html">here</A></=
B>.=20
<P><B>The following provide information on garbage collection in =
general</B>:=20
<P>Paul Wilson's <A href=3D"ftp://ftp.cs.utexas.edu/pub/garbage">garbage =

collection ftp archive</A> and <A=20
href=3D"ftp://ftp.cs.utexas.edu/pub/garbage/gcsurvey.ps">GC survey</A>.=20
<P>The Ravenbrook <A href=3D"http://www.memorymanagement.org/">Memory =
Management=20
Reference</A>.=20
<P>David Chase's <A href=3D"http://www.iecc.com/gclist/GC-faq.html">GC =
FAQ</A>.=20
<P>Richard Jones' <A=20
href=3D"http://www.ukc.ac.uk/computer_science/Html/Jones/gc.html">GC =
page</A> and=20

⌨️ 快捷键说明

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