[Gc] Re: Mentality of c/c++ programmers when it comes to gc

Achilleas Margaritis axilmar at otenet.gr
Sun Dec 23 02:44:06 PST 2007

As a programmer that's recently been there, here are my two bits of 
wisdom (for version 7.0):

Invoke GC_INIT (from the main thread) once before using the collector 
(either when allocating memory or doing any other thing), so as that the 
collector is initialized properly.

Start your threads with GC_CreateThread or GC_pthread_create (depending 
on your operating system).

Allocate memory with GC_MALLOC (for blocks that contain pointers) or 
GC_MALLOC_ATOMIC (for blocks that do not contain pointers).

Register a finalizer with the macro GC_REGISTER_FINALIZER.

Invoke GC_gcollect to start a collection manually.

For compiling the gc, you have to look in the various documents, 
makefiles and source code to find how to do it. With Microsoft 
compilers, your best option is to rename the file 
NT_STATIC_THREADS_MAKEFILE to MAKEFILE, open a command line window, type 
'vcvars32.bat', then type 'nmake nodebug=1 CFG="gc - Win32 Release"' to 
make the release version or 'nmake CFG="gc - Win32 Debug"' to make a 
debug version. I personally have two directories with the gc, one with 
the debug version and one with the release version, and I have renamed 
the debug version gcd.lib in order to use it in the same project with 
the release version.

I think mr Boehm should spend a little time clearing the project up, 
because I suspect many first-timers have been discouraged by its state. 
When you download it for the very first time, it's like being blind and 
in the dark. It took me 3 weeks from start to finish to completely 
understand how to use it, and this was the 3rd time that I tried it 
(previous attempts failed desperately).

If you have any more questions, feel free to ask.

O/H Bryan Ewbank έγραψε:
> Interestingly, I am a C++ programmer that has been poking around at
> gc, but have not had much success in finding how-to documents with
> enough detail to drop it into my current projects.
> I'm stuck with pools and reference counts because they were available
> quickly (e.g., the boost libraries).  Maybe I'm in the minority, but I
> don't deny it's usefulness; I wish I could use it as easily as the
> other options...
> - Bryan
> On Dec 22, 2007 1:29 PM, S M Ryan <wyrmwif at rawbw.com> wrote:
>>> I've been talking with various c/c++ programmers over the globe
>>> about the benefits of garbage collection...90% of the people I've
>>> talked with are negative to using gc. They propose memory pools or
>>> reference counting as the solution to memory management problems.

More information about the Gc mailing list