garbage collection with digital mars compiler

H

HalcyonWild

Hi,

I installed the free version(command line only) of the digital mars c++
compiler.

It said it features a garbage collection mechanism, but there was no
documentation. I figured out that you have to extend the class
mentioned in gc.h file. But it does not compile. Does the compiler
automatically extend the gc classes, while compiling.

I tested for the memory leak by running main in a very long loop and
commenting out the delete statements. It does fail and exits with
unpredictable results. Sometimes, an illegal memory access error and
sometimes, just writes out garbage to the command line and terminates
without any error.

Please tell me, in short, how to use GC in digital mars compiler. I
will try to work my way around. I dont know if I am on the right track.


Thanks.
 
M

mlimber

HalcyonWild said:
Hi,

I installed the free version(command line only) of the digital mars c++
compiler.

It said it features a garbage collection mechanism, but there was no
documentation. I figured out that you have to extend the class
mentioned in gc.h file. But it does not compile. Does the compiler
automatically extend the gc classes, while compiling.

I tested for the memory leak by running main in a very long loop and
commenting out the delete statements. It does fail and exits with
unpredictable results. Sometimes, an illegal memory access error and
sometimes, just writes out garbage to the command line and terminates
without any error.

Please tell me, in short, how to use GC in digital mars compiler. I
will try to work my way around. I dont know if I am on the right track.


Thanks.

This question is off-topic here since it is concerned with a particular
vendor's garbage collector, but see the FAQ:

http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.26

and following.

Cheers! --M
 
H

HalcyonWild

mlimber said:
This question is off-topic here since it is concerned with a particular
vendor's garbage collector, but see the FAQ:

-----
Not offtopic really. It is not digitals garbage collector. It is the
Hans Boehm garbage collector which they bundle with their compiler.
-----

-----
Thanks for the link. I did go through the Boehms gc site *again*.
Cannot find the link which has source code samples, or anything that
has instructions to use the same. I went through the source file for
gc.h, and tried a few things, but no success.

If anyone has used this GC, please let me know how to use it.

Probably the subject line gave the wrong impression. It is a general
GC, and not particular to Digital mars , who just bundle it. Changing
the subject line.
-----
 
M

mlimber

[snip]

Still off-topic. According to
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9, to be
on-topic "your question must be answerable by looking into the C++
language definition as determined by the ISO/ANSI C++ Standard
document, and by planned extensions and adjustments."

You, however, are concerned with a specific, non-standard algorithm
(and a particular implementation of it, at that). See that same FAQ for
some suggestions on better forums to post in.

Cheers! --M
 
H

HalcyonWild

mlimber said:
[snip]

Still off-topic. According to
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9, to be
on-topic "your question must be answerable by looking into the C++
language definition as determined by the ISO/ANSI C++ Standard
document, and by planned extensions and adjustments."

You, however, are concerned with a specific, non-standard algorithm
(and a particular implementation of it, at that). See that same FAQ for
some suggestions on better forums to post in.

Cheers! --M

ahh well, I will look for that. any idea what that forum might be. BTW,
if anyone has any idea , please post, as I want to avoid multiposting,
posting the same thing to some other forum.
Thanks.
 
W

Walter Bright

HalcyonWild said:
I installed the free version(command line only) of the digital mars c++
compiler.

It said it features a garbage collection mechanism, but there was no
documentation.

I'd start with www.digitalmars.com/rtl/gc.html
I figured out that you have to extend the class
mentioned in gc.h file.

There isn't a class or a struct in \dm\include\gc.h. The API is described in
www.digitalmars.com/rtl/gcheader.txt. It has a C interface, not a C++ one,
so there won't be a need for class extending to use it.

The gc included with Digital Mars C/C++ is the Hans Boehm garbage collector.
For lots of details about it, see Hans' web site at
http://www.hpl.hp.com/personal/Hans_Boehm/gc/.

-Walter Bright
www.digitalmars.com C, C++, D programming language compilers
 
H

HalcyonWild

Walter said:
I'd start with www.digitalmars.com/rtl/gc.html


There isn't a class or a struct in \dm\include\gc.h. The API is described in
www.digitalmars.com/rtl/gcheader.txt. It has a C interface, not a C++ one,
so there won't be a need for class extending to use it.

The gc included with Digital Mars C/C++ is the Hans Boehm garbage collector.
For lots of details about it, see Hans' web site at
http://www.hpl.hp.com/personal/Hans_Boehm/gc/.

-Walter Bright
www.digitalmars.com C, C++, D programming language compilers


Thanks a lot Walter. Great to hear from you.

I did visit those links. You mean to say, I must rather use gc_malloc
function to allocate memory and forget about it. No need to free the
memory. I will try that out.

I did see the gc.h file included in the zip install file. I might be
mistaken, but I saw the new operator implemented somewhere. Also, going
through it does seem to be a bit confusing (for me atleast, I dont have
much experience on C++).

A humble suggestion :) Please include some code samples too on the
Digital Mars site.
 
W

Walter Bright

HalcyonWild said:
Thanks a lot Walter. Great to hear from you.

I did visit those links. You mean to say, I must rather use gc_malloc
function to allocate memory and forget about it. No need to free the
memory. I will try that out.

I did see the gc.h file included in the zip install file. I might be
mistaken, but I saw the new operator implemented somewhere. Also, going
through it does seem to be a bit confusing (for me atleast, I dont have
much experience on C++).

A humble suggestion :) Please include some code samples too on the
Digital Mars site.

I hate to say it, but using garbage collection with C++ is an advanced
technique. The language doesn't really support it, and so things get mucked
about under the hood to make it work. There are a lot of things to watch out
for, like interaction with APIs that also manage memory their own way. Once
you do get gc working with C++, though, it can be pretty nice.

Why not start out with a C++ like language designed to work with gc, like
the D programming language?

-Walter Bright
www.digitalmars.com C, C++, D programming language compilers
www.digitalmars.com/d/ the D programming language
 
H

HalcyonWild

Walter said:
I hate to say it, but using garbage collection with C++ is an advanced
technique. The language doesn't really support it, and so things get mucked
about under the hood to make it work. There are a lot of things to watch out
for, like interaction with APIs that also manage memory their own way. Once
you do get gc working with C++, though, it can be pretty nice.

Why not start out with a C++ like language designed to work with gc, like
the D programming language?




Sure. I have the D prog lang setup unzipped here, on my machine. I do
keep trying things on it, though I have not seen it or the digital mars
site since few months, because of workload at my job on Java. Also, the
D pages seem to have updated, or I found the right links for D this
time. I will try it further.

Also, my earlier suggestion again. More docs and code samples. Actually
, it is lack of enough samples and documents that keep me from trying
out "heavier" things on D, and exploring it further. There are
documents on the digital mars site, and also code snippets on the D
pages, but they are more like manuals rather than books, like the
"complete reference series" of mcgraw hill, or the "learning" series of
oreilly. More well commented code samples will suffice. Say like, more
complete code samples (working) on window manipuation, XML parsing, etc
in D.

It will take time for more books, and documents to come out in the
market, on D prog lang, IMHO, as it gains prevelance.

I also found out where I found the new operator overloaded. It is in
gc_cpp.h. I figured that gc_cpp would be the one to include, since I
was making a C++ program. It sure is complicated.

Thanks.
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top