J
Jerry Coffin
[ ... ]
Not really. A typical gc in C++ is added on after the fact, so it does
conservative collection -- since it doesn't know what is or isn't a
pointer, it treats everything as if it was a pointer, and assumes that
whatever if would point at if it was as pointer is live memory. Of
course, some values wouldn't be valid pointers and are eliminated.
It does NOT, however, know with any certainty that a particular value IS
a pointer -- some definitely aren't (valid) pointers, but others might
or might not be. Since it doesn't know for sure which are pointers and
which are just integers (or whatever) that hold values that could be
pointers, it can't modify any of them. It has enough information to do
garbage collection, but NOT enough to support compacting the heap.
Good thing I neither said nor implied that it is, then. However,
all Java VMs that I know of support it. for the obvious reason that
GCs which don't compact would fail pretty quickly with heap
fragmentation [1]. Most C++ implementations don't support it, because
their pointers are implemented as machine addresses.and they lack a
mechanism to fix up the pointers after a compaction.
1. Plus the fact that if you have enough information to do GC, you
have more than enough to make compaction work.
Not really. A typical gc in C++ is added on after the fact, so it does
conservative collection -- since it doesn't know what is or isn't a
pointer, it treats everything as if it was a pointer, and assumes that
whatever if would point at if it was as pointer is live memory. Of
course, some values wouldn't be valid pointers and are eliminated.
It does NOT, however, know with any certainty that a particular value IS
a pointer -- some definitely aren't (valid) pointers, but others might
or might not be. Since it doesn't know for sure which are pointers and
which are just integers (or whatever) that hold values that could be
pointers, it can't modify any of them. It has enough information to do
garbage collection, but NOT enough to support compacting the heap.