471,612 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,612 software developers and data experts.

Boehm's garbage collector: beginner's questions

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
Jul 22 '05 #1
6 2898
Atip Asvanund wrote:
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 $@ $<
queries
I don't see what this line was for.
I also include the gc.h file in my source.
This will be "#include <gc.h>" now.
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.

--
Regards,
Buster.
Jul 22 '05 #2
Atip Asvanund wrote:
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 $@ $<
queries
I don't see what this line was for.
I also include the gc.h file in my source.
This will be "#include <gc.h>" now.
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.

--
Regards,
Buster.
Jul 22 '05 #3
Atip Asvanund wrote:

#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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #4
Atip Asvanund wrote:

#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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #5
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.

Jul 22 '05 #6
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.

Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Atip Asvanund | last post: by
8 posts views Thread by HalcyonWild | last post: by
18 posts views Thread by Larry Herbinaux | last post: by
13 posts views Thread by Mingnan G. | last post: by
2 posts views Thread by ajayraj | last post: by
5 posts views Thread by malkarouri | last post: by
3 posts views Thread by Razii | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.