[patch] Move loop structures to gc memory

Mark Mitchell mark@codesourcery.com
Thu May 17 04:18:00 GMT 2007


Alexandre Oliva wrote:

>> In our current system, you must GC-allocate this temporary memory.
> 
> This doesn't seem like the single root cause of the problem to me.
> 
> AFAICT, the root cause of the problem is that you can't dynamically
> register and deregister GC roots.

It's both. :-)

You've nailed one of the key problems: you need to dynamically register
and deregister roots.  But, one of the reasons you need that ability is
precisely so that you can have the roots live in non-GC memory, so that
you can use faster allocation/deallocation methods.

What you want to do is like:

  struct s {
    ...
    tree t;
    ...
  };

  struct s* p = some_alloc (sizeof (s));
  p->t = build1 (...);
  ggc_register_root (&p->t);
  ...
  ggc_collect ();
  ...
  ggc_deregister_root (&p->t);
  some_free (p);

In order to be able to use some_{alloc,free} (presumed to be faster, or
otherwise better, that ggc_alloc/ggc_free), you have to have
ggc_{register,deregister}_root.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713



More information about the Gcc-patches mailing list