Boehm's garbage collector: beginner's questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Atip Asvanund

    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
  • Buster

    #2
    Re: Boehm's garbage collector: beginner's questions

    Atip Asvanund wrote:
    [color=blue]
    > Dear sirs,[/color]

    FYI, it's conventional to omit greetings and valedictories on usenet.
    [color=blue]
    > 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.[/color]

    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
    [color=blue]
    > 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[/color]

    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 $@ $<
    [color=blue]
    > queries[/color]

    I don't see what this line was for.
    [color=blue]
    > I also include the gc.h file in my source.[/color]

    This will be "#include <gc.h>" now.
    [color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > 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.[/color]

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

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

    Sorry, no idea.

    --
    Regards,
    Buster.

    Comment

    • Buster

      #3
      Re: Boehm's garbage collector: beginner's questions

      Atip Asvanund wrote:
      [color=blue]
      > Dear sirs,[/color]

      FYI, it's conventional to omit greetings and valedictories on usenet.
      [color=blue]
      > 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.[/color]

      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
      [color=blue]
      > 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[/color]

      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 $@ $<
      [color=blue]
      > queries[/color]

      I don't see what this line was for.
      [color=blue]
      > I also include the gc.h file in my source.[/color]

      This will be "#include <gc.h>" now.
      [color=blue]
      > 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.[/color]

      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.
      [color=blue]
      > 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.[/color]

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

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

      Sorry, no idea.

      --
      Regards,
      Buster.

      Comment

      • Kevin Goodsell

        #4
        Re: Boehm's garbage collector: beginner's questions

        Atip Asvanund wrote:
        [color=blue]
        >
        > #define malloc(n) GC_malloc(n)
        > #define calloc(m,n) GC_malloc((m)*( n))
        >[/color]

        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.

        Comment

        • Kevin Goodsell

          #5
          Re: Boehm's garbage collector: beginner's questions

          Atip Asvanund wrote:
          [color=blue]
          >
          > #define malloc(n) GC_malloc(n)
          > #define calloc(m,n) GC_malloc((m)*( n))
          >[/color]

          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.

          Comment

          • JaSeong Ju

            #6
            Re: Boehm's garbage collector: beginner's questions

            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.

            Comment

            • JaSeong Ju

              #7
              Re: Boehm's garbage collector: beginner's questions

              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.

              Comment

              Working...