lkml.org 
[lkml]   [2004]   [Jul]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Garbage Collection and Swap


John Richard Moser wrote:

>
> THE GARBAGE COLLECTOR WANDERS AROUND IN THE ENTIRE HEAP, AND IN SOME
> CASES IN OTHER PARTS OF RAM, LOOKING FOR WHAT LOOKS LIKE POINTERS TO
> YOUR ALLOCATED DATA.
>

Whose GC does this?

I get the impression that the Java VM, for instance, knows what
variables are pointers (well, references) and only considers those. It
also knows every object that has even been allocated. It scans over
every pointer it knows about (the "mark" phase), and then it scans over
every dynamically allocated memory block (the "sweep" phase) and removes
all that have no references.

There is anecdotal evidence that this approach sometimes can improve
performance over "manual" freeing because freeing can be done in bulk.

Java GC works very well, and it's a huge improvement over the "manual"
method, because it almost completely eliminates memory leaks (if you
really want a memory leak, you can find a way to make it happen).
Now, if you're talking about trying to apply GC to C code, it's an
entirely different matter. C wasn't designed with GC in mind. The very
fact that you can do MATH on pointers in C makes reliable GC nearly
impossible, although any reasonable attempt would certainly be better
than your assumption that something would "go scanning through memory
looking for things that look like pointers." That would be horribly
stupid. Better would be to have the compiler emit code that registers
pointers with something that keeps track of them, but that's still a
huge can of worms when you consider someone malloc'ing N bytes, storing
a (void *), and then later assigning that value to a struct pointer.

No, I don't think GC in C is feasible.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:04    [from the cache]
©2003-2011 Jasper Spaans