[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Dec 30 15:08:40 2003 
Subject:Re: Comparing Garbage Collectors 
From:David Young 
Volume-ID:1031230.04 

On Mon, 29 Dec 2003, Aaron Sloman wrote:

> [we] focused on mechanisms to allow users to reduce the frequency of
> garbage collections and the total amount of garbage generated by
> certain programs. These mechanisms included the following:
>
> ...
>
> o mechanisms for maintaining 'free lists' so that items known by the
> programmer to be garbage could be returned to a free list for re-use,
> ...
> (Users can implement their own versions to some extent, e.g. a mechanism
> for handling free lists of vectors of different sizes.)

I thought I'd mention my contribution to this, since it took a lot of
thought to get it right, but I believe I did get it right in the end.

I write programs that use lots of large arrays and time for garbage
collections can become significant. A while ago I produced an
array-caching mechanism which for my programs drastically reduces GC
time and which I find very convenient. Two features are:

    o The programmer does not have to explicitly release arrays; rather
    when requesting a new array a "tag" is passed. The array returned
    may share storage with any array of the same type which was
    previously created using the same tag. This approach lends itself
    particularly to recycling temporary work arrays, though I use it
    almost everywhere now. Memory may be reused even if the array size
    changes.

    o When a GC does occur, cached arrays are released as garbage. Thus
    no extra memory is tied up long term. However, memory that would
    otherwise be waiting to be GC'ed is available for reclaiming when an
    array is needed.

There are some complications which it took me a while to get right, but
I've been using this successfully for years now. The code and
documentation may be found at:

http://www.cs.bham.ac.uk/research/poplog/popvision/lib/oldarray.p
http://www.cs.bham.ac.uk/research/poplog/popvision/help/oldarray

David