[Gc] Questions on boehm-gc, fragmentation, and low memory
makholm at octoshape.com
Wed Jul 8 10:33:05 PDT 2009
> - Does boehm-gc do something to avoid/minimize fragmentation ?
Yes, insofar as "doing something" amounts to not using the stupidest
algorithm imaginable. It divides the heap into pages and allocates
only same-sized objects from each page. If your application uses only
objects of a few different sizes, you shouldn't have worries about
If many of your objects are just a bit larger than half a page, you lose out.
Things are less clear to me concerning multi-page objects. At that level
the OS's virtual memory support usually kicks in and makes fragmentation
less of a problem. This may not be true on an embedded system without a
large backing store.
> - Is there any "moving"/compacting implementation of boehm gc, and if
> not, would it be possible ?
No, that would not be possible. The fundamental design choice for the BDW
GC is that it is "conservative": it does not know exactly which registers
and local variables contain pointers, so if it were to decide to move heap
objects around, it would have no way to safely patch up all pointers to the
moved objects. (Some of the words that look like pointers to a moved object
might actually be non-pointer data).
In general a collector that moves objects demands either deep integration
with the compiler's code generator (such that every stack frame is marked
up with exact where-are-the-pointers information), or very tight discipline
in the source code of the client program such that moveable pointers are never
stored in local variables across points calls the collector might run. The
latter is probably compatible with programmer sanity only for generated code
and/or when implementing a virtual machine.
More information about the Gc