[Gc] BoehmGC7 and VC8
martin.wartens at mymail.ch
Sun Jul 8 17:13:00 PDT 2007
I tried to make the Boehm gc 7 run with VC8 (Visual Studio 2005) and wanted to
share my experiences.
Flags ("Preprocessor definitions") that seem to work are:
For debug and release modes likewise.
Note that GC_WIN32_THREADS is not necessary, GC_THREADS is ok. The old __STDC__
flag is not needed anymore. I am not sure if the GC_BUILD flag does something
important, it seems to work without. Adding the PARALLEL_MARK flag gives an
error "Cannot implement AO_compare_and_swap_full on this architecture." which I
did not track further.
As noted by Christoph Meessen, there seems to be a problem with the C++
initialization phase. Calling "GC_INIT" in main() is useless for a C++ program,
since static objects are initialized already before entering main. In
if (!GC_is_initialized) GC_init();
just before the two instances of "GC_ASSERT(GC_is_initialized);"
To benefit from the garbage collector, file gc_cpp.cc has to be modified to use
GC_MALLOC instead of GC_MALLOC_UNCOLLECTABLE. (several instances)
Using REDIRECT_MALLOC=GC_malloc would be nice to have really all memory
allocation controlled by the gc. The problem here are several special
allocation functions that are used asymmetrically with a standard call to free.
When REDIRECT_MALLOC=GC_malloc is defined, the special allocation functions are
not caught by the gc, but the free is, which leads to a crash. In debug mode
there are _malloc_dbg and _calloc_dbg from dbgheap.c that have to be redefined,
as well as new operators from xdebug.cpp. In release mode, special functions
_malloc_crt and _calloc_crt are used during the init phase. I tried to redirect
them to the gc, but that caused an error when running the program with the
debugger: it stopped somewhere in the collection code during the init phase. To
overwrite the system malloc, a special linking technique has to be used:
"gc.lib ...other libs in the middle... LIBCMTD.lib" (or LIBCMT for release)
"Ignore specific library":
"Command Line->Additional Options:"
In line 125 of gc_allocator, it must be
GC_type_traits<GC_Tp> traits = GC_type_traits<GC_Tp>();
to stop a warning.
GC_ASSERTIONS does not work, there are some extern function definitions missing.
The following files were included into the project:
More information about the Gc