[Gc] Re: gc_typed.h

Ludovic Courtès ludovic.courtes at laas.fr
Fri May 12 00:31:38 PDT 2006


Hi,

"Boehm, Hans" <hans.boehm at hp.com> writes:

> It is current, minimally tested by gctest, but I believe infrequently
> used.  I don't recall any documentation beyond the somewhat cryptic
> comments in the header file.  There is some small performance cost to
> supporting it, so it wouldn't have stayed there if I felt it was
> useless.

In the process of porting Guile to `libgc', I use it to implement "weak
pairs" and it seems to work fine so far.  A weak pair is (roughly) a
pair of pointers where one of these two pointers (or both) is to be
registered as a "disappearing link".  Thus, the word containing this
(weak) pointer must not be scanned.

As an example, here is a (slightly simplified) code snippet that might
help you:

  /* Our two-word structure.  */
  typedef struct
  {
    void *word_0;
    void *word_1;
  } scm_t_cell;

  /* The type descriptor.  */
  static GC_descr wcar_cell_descr;

  /* Return a weak-car pair, i.e., a pair whose first word should _not_ be
     scanned.  */
  static scm_t_cell *
  scm_weak_car_cell (SCM car, SCM cdr)
  {
    scm_t_cell *cell;

    cell = (scm_t_cell *)GC_malloc_explicitly_typed (sizeof (*cell),
                                                     wcar_cell_descr);

    /* ... */

    return (cell);
  }

  void
  initialize_the_type_descriptor (void)
  {
    GC_word wcar_cell_bitmap[GC_BITMAP_SIZE (scm_t_cell)] = { 0 };

    /* Only the second word must be scanned for pointers.  */
    GC_set_bit (wcar_cell_bitmap, GC_WORD_OFFSET (scm_t_cell, word_1));
    wcar_cell_descr = GC_make_descriptor (wcar_cell_bitmap,
                                          GC_WORD_LEN (scm_t_cell));

  }

Thanks,
Ludovic.



More information about the Gc mailing list