[hellogcc] Re: [hellogcc] Re: [hellogcc] Re: [hellogcc] Re: [hellogcc] 哪位大牛能简单介绍一下GCC里面的垃圾收集功能

  • From: Mingjie Xing <mingjie.xing@xxxxxxxxx>
  • To: hellogcc@xxxxxxxxxxxxx
  • Date: Tue, 28 Jun 2011 20:29:02 +0800

在 2011年6月28日 下午3:29,Yao Qi <qiyaoltc@xxxxxxxxx> 写道:
> 关于mark-and-sweep,是标准的GC算法,也可能是最初级的吧。这个不是问题。
>
> 问题是:
> 哪里有显示调用垃圾搜集?

搜索源码 ggc_ 可以发现有许多地方显式调用了ggc_开头的函数。其中ggc_free函数,看起来应该是做垃圾搜集的。

> 为啥用GTY标记,就能成为root?

这就涉及到了root集的定义。龙书上如是说:“我们把所有不需要对任何指针解引用就可以被程序直接访问的数据称为根集(root set)”。

gcc internals里如是说:

In addition to keeping track of types, the type machinery also locates
the global variables (roots) that the garbage collector starts at.
Roots must be declared using one of the following syntaxes:

    * extern GTY(([options])) type name;
    * static GTY(([options])) type name;

xmj

Other related posts: