Boehm's garbage collector: beginner's questions

A

Atip Asvanund

Dear sirs,

I am trying to learn how to use Boehm's garbage collector:
http://www.hpl.hp.com/personal/Hans_Boehm/gc/ on a Linux machine. I am
a beginner, and I find its documentation inadequate. I have followed
all instructions for installation, yet I still have the following
questions.

1) The instruction said to include the header file, and link to the
library file. I was wondering if I am doing it correctly in my
makefile:

-bash-2.05b$ more makefile
queries: queries.cpp queries.h /new/usr2/xxx/gc/include/gc.h
g++ -g -o3 queries.cpp /new/usr2/xxx/gc/lib/libgc.a -o
queries

I also include the gc.h file in my source.

2) The instruction said specifically to run "make c++" after a regular
make. I get the following error message, while the regular make and
make install works. I am using c++, so will this cause a problem?

-bash-2.05b$ make c++
make: *** No rule to make target `c++'. Stop.

3) I am using STL for most of my complex datasets. Does STL work at
all with Boehm? If it does, does it work automatically, or do I need
to specify some special options. What will happen if I use the
following defines:

#define malloc(n) GC_malloc(n)
#define calloc(m,n) GC_malloc((m)*(n))

Other than STL, I use my own codes for the rest of the stuff, so I am
not so worried.

4) In C++ do I include gc.h or do I use a different file?

5) Is there a gentler introduction to Boehm with examples that I can
use?

Thank you very much,

Joe
 
B

Buster

Atip said:
Dear sirs,

FYI, it's conventional to omit greetings and valedictories on usenet.
I am trying to learn how to use Boehm's garbage collector:
http://www.hpl.hp.com/personal/Hans_Boehm/gc/ on a Linux machine. I am
a beginner, and I find its documentation inadequate. I have followed
all instructions for installation, yet I still have the following
questions.

Is there a newsgroup, mailing list, faq, etc., listed on that site?
Your enquiry is off-topic for comp.lang.c++ - see the welcome message
at http://www.slack.net/~shiva/welcome.txt
1) The instruction said to include the header file, and link to the
library file. I was wondering if I am doing it correctly in my
makefile:

-bash-2.05b$ more makefile
queries: queries.cpp queries.h /new/usr2/xxx/gc/include/gc.h
g++ -g -o3 queries.cpp /new/usr2/xxx/gc/lib/libgc.a -o

It is not necessary to list gc.h as a prerequisite of queries, unless
you are going to edit that file.

A correct and idiomatic makefile might go something like this (and if
its filename is Makefile, with a capital 'M', you won't need to specify
the filename when you make).

CXX=g++
CPPFLAGS=-idirafter /new/usr2/xxx/gc/include
CXXFLAGS=-g -o3
LDFLAGS=-L /new/usr2/xxx/lib
LDLIBS=-lgc

all: queries

queries: queries.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)

queries.o: queries.cpp queries.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<

I don't see what this line was for.
I also include the gc.h file in my source.

This will be "#include said:
2) The instruction said specifically to run "make c++" after a regular
make. I get the following error message, while the regular make and
make install works. I am using c++, so will this cause a problem?

-bash-2.05b$ make c++
make: *** No rule to make target `c++'. Stop.

Oh! Well, there must have been a makefile provided with the
distribution, or maybe some instructions for adding a target
called 'c++' to your own makefiles. I don't know, sorry.
3) I am using STL for most of my complex datasets. Does STL work at
all with Boehm? If it does, does it work automatically, or do I need
to specify some special options. What will happen if I use the
following defines:

#define malloc(n) GC_malloc(n)
#define calloc(m,n) GC_malloc((m)*(n))

Other than STL, I use my own codes for the rest of the stuff, so I am
not so worried.

By default the standard containers use the std::allocator which uses new
and delete. You may have to provide a custom allocator. (Ouch).
4) In C++ do I include gc.h or do I use a different file?

Some header files are written to be 'bilingual', but not all.
5) Is there a gentler introduction to Boehm with examples that I can
use?

Sorry, no idea.
 
K

Kevin Goodsell

Atip said:
#define malloc(n) GC_malloc(n)
#define calloc(m,n) GC_malloc((m)*(n))

Several possible problems with this.

First, what if malloc and/or calloc is already #defined? You'd better
#undef them first.

Second, unless GC_malloc() zeros out the buffer it returns, you are
changing the semantics of calloc().

Third, you shouldn't use malloc(), calloc() and friends at all in C++
(unless you have a very good reason, which is rare). They don't do
proper initialization and destruction of objects.

-Kevin
 
J

JaSeong Ju

I have not used Boehms garbage collector yet.
But I do know that in the March 2003 issue of
C/C++ Users Journal, there was an article
about Boehms garbage collector, and how to use it.

If you are not aware of this, then it might be
profitable for you to read it from local library.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top