[Gc] Per-type displacement

Ludovic Courtès ludo at gnu.org
Fri Sep 19 05:14:24 PDT 2008


Guile's `struct' objects are such that they can have N extra words that
are hidden from the application roughly as follows:

  void *
  make_struct (size_t n_extra, size_t user_size)
    char *p = GC_MALLOC (n_extra + user_size);

    return p + n_extra;

Registering a displacement globally for each value of N_EXTRA may lead
to excess memory retention, especially since most other Guile objects
("cells") are 2 or 4 word long.

Ideally, I'd create a `GC_desc' and somehow specify valid displacements
that apply specifically to this type, which the `gc_typed.h' API
currently doesn't allow.

Does that seem like a reasonable approach?  Can it be approximated using
the current API?  Is it just that this allocation paradigm (returning a
pointer in the middle of the object) is questionable?  :-)


More information about the Gc mailing list