[gambit-list] Re: Re: Regarding garbage collection
Marc Feeley
feeley at iro.umontreal.ca
Thu Sep 10 08:27:54 EDT 2009
On 9-Sep-09, at 10:42 PM, peter lo wrote:
> By the way, I am currently trying to reduce the allocation of short-
> lived objects, I am sure there are general tips on the web about
> this, but I am not sure if there are tips more specific to Gambit
> Scheme, taking into account its garbage collector.
I suggest that you represent your "lists" using extensible vectors,
implemented with plain vectors. The value at index 0 is really the
number of active elements in the extensible vector. When the vector
is full, a slightly longer (by a factor of say 20% more) is allocated
and the previous content is copied to it. This representation is up
to 6 times more compact than the list representation for long enough
"lists", when using Gambit. That's because each element in the list
requires a pair, and each pair occupies 6 words of memory, header+car
+cdr=3, but they are movable objects so the same space must be
reserved in the "to-space". For long enough vectors (255 elements or
more) each element occupies one word because the vector is "still" (no
need to reserve space in the "to-space").
Marc
More information about the Gambit-list
mailing list