[Gc] Ask for advice on small objects

Henning Makholm Henning at octoshape.com
Tue Mar 11 09:46:22 PST 2008


Juan Jose Garcia-Ripoll writes:

[on tag bits in the least-siginficant end of pointers]

> 1) Is this supported by the garbage collector? Will the type tag "1"
> or pointer displacement cause problems for detecting live conses?

Yes, it is supported. For all the collector knows, you're treating your
memory as an array of bytes and keeping a pointer into it, which is
perfectly legal.

> Does this work even without the option to detect interior pointers?

I shouldn't think so. But you should be able to call
GC_register_displacement(1) to make it work even if you set
GC_all_interior_pointers to 0.

> 2) The garbage collector reports 16 bytes being allocated for every
> cons. Is there a way to reduce this?

The reason 16 bytes is allocated by default is that the C standard
guarantees that you can advance a pointer to one past the last element
of an array and later step back into the array. Therefore the garbage
collector adds one byte to each allocation, such that if it needs to
trace a one-past-last-element pointer, it can still deduce which object
to keep alive. This increases the 8 bytes you ask for to 9, which then
gets rounded up to 16 because allocated blocks are 8-byte aligned on
many platforms.

If you know you're never using the one-past-last-element feature, you can
turn it off by building the collector with DONT_ADD_BYTE_AT_END or setting
GC_all_interior_pointers to 0.

--
Henning Makholm
OctoShape ApS



More information about the Gc mailing list