Graham Barr <[EMAIL PROTECTED]> wrote:
> Ouch. I have quite often had applications that would use several hundred MB
> now. If I would need double that, then that is going to hurt. I am not
> familiar with copying collector GC, does anyone have a pointer to any
> papers etc.

The basic operation of a copying collector is that you divide your memory
in two. Then a malloc looks roughly like:

heap+=size; 
if (heap <= MAX)
    return heap
else {
    do_gc();
    return heap=+size;
}

There is no free(), and malloc just doles out memory till it reaches
the top of it's half. At this point the garbage collector is invoked,
which scans the 'root nodes' (ie pointers in global vars, on the stack, etc),
and for each bit of live data it finds, it copies that data into the other
half of memory, starting at the base and working upwards. It recursively
follows pointers within data structures so that eventually all reachable
live data has been copied to the new half. It then goes through and fixes
all pointers to point at the new locations. Finally, the heap pointer is
set to point to the end of the copied data in the new half.
The big advantage is that no processing whatsoever needs to be done on
dead data, not even the overhead of a call to free(). As a bonus, memory
is compacted, and locality of reference tends to be good.

Of course, that's the basic principle, there's a lot more to it than that
to make it efficient and not require *all* memory to be split in two etc.

By the way, the _Garbage Collection_ book is very worthy, but like
Neitsche, "it gets a bit boring after a while." [*]

Dave M.

[*] A friend of mine with a philosophy degree was once asked to write
an article on Neitsche. After much thought, he came up with:

"Neitsche: he gets a bit boring after a while."

Reply via email to