Garbage Collector examples ?

F

Fab

Hi !

Maybe somebody has used a GC - I think to Hans Boehm's one, but
other, if any, are welcome -. I need to use a GC in order to program an
interpreter for a functional language. Memory handling would be
otherwise difficult too much. I read that the use of Boehms'GC - well
fit for C - was generally complicated enough and particularly for STL.

I confess I considered to switch to Java for this reason...
But what about SGI hash extension in Java ? What about Boost Spirit or
Graph library ? I don't know. Maybe Java does not provide such packages
?

However I prefer to stay in C++ world :
- save learning time
- produce speed code, using powerful STL and Boost

Please do you have simple examples of GC use :
- in any C++ program,
- in a STL program.


Thanks

Fabrice
 
S

Salt_Peter

Fab said:
Hi !

Maybe somebody has used a GC - I think to Hans Boehm's one, but
other, if any, are welcome -. I need to use a GC in order to program an
interpreter for a functional language. Memory handling would be
otherwise difficult too much. I read that the use of Boehms'GC - well
fit for C - was generally complicated enough and particularly for STL.

I confess I considered to switch to Java for this reason...
But what about SGI hash extension in Java ? What about Boost Spirit or
Graph library ? I don't know. Maybe Java does not provide such packages
?

However I prefer to stay in C++ world :
- save learning time
- produce speed code, using powerful STL and Boost

Please do you have simple examples of GC use :
- in any C++ program,
- in a STL program.


Thanks

Fabrice

I respectfully beleive that memory handling is easier without a GC,
since many of these fail to function properly anyways and have a
considerable impact on performance, not to mention the critical issue
of accountability - which is the key here. The best GC is you, a smart
pointer or better yet, no pointers at all.
I can understand in C where references don't exist, but not in C++.
Allocation == ownership, thats the law. In fact, C++ has a term for it:
RAII
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization

Incidentally, without denigrating Java's reason to be, it would be a
much better language if it did not have the need for a GC. This is
specially relevent since a Java reference is a dumb raw pointer. If
Java implemented its references as smart references based on scope, not
just use, i'm convince without a doubt that Java would run faster, gain
in stability, and be the premium language in use today.

Only an opinion and not neccessarily the correct one.

My big pet peeve with Java is that most example codes and tutorials
teach Java programmers to regenerate Objects instead of reusing them.
Why? Cause the garbage collector takes away the a programmer's
responsability_ to_manage his code's resources. Thats a shame,
specially __with__ a GC!!
 
K

Kai-Uwe Bux

Salt_Peter said:
I respectfully beleive that memory handling is easier without a GC,
since many of these fail to function properly anyways and have a
considerable impact on performance, not to mention the critical issue
of accountability - which is the key here. The best GC is you, a smart
pointer or better yet, no pointers at all.
I can understand in C where references don't exist, but not in C++.
Allocation == ownership, thats the law. In fact, C++ has a term for it:
RAII
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
[Java discussion snipped]

I would be with you if the OP had just asked about using GC for some random
project. However, the OP wants to write an interpreter for a functional
language. I conjecture that the language provides a data type for recursive
lists (list that contain atoms as well as lists and can even contain cyclic
references like: the last element of a list could be the list itself) or
something similarly devious. In that case, implementing this very data type
amounts to solving the general problem of garbage collection. Thus, it is
very reasonable not to that yourself but to rely on a ready to use
solution: (a) it takes less programming time and (b) very likely you won't
beat the garbage collector anyway as it was optimized already by people
specializing in garbage collection.


Best

Kai-Uwe Bux
 
F

Fab

Thank you for your interesting answers !


Salt_Peter, I agree with you it is a good thing to responsible of an
accurate memory
management. GC looks like blurred at best.
It is indeed the first time I feel the need of a GC. The reasons are
exactly these Kai-Uwe Bux exposes here.
Moreover, Mc Carthy created Lisp and Garbage Collection too ( I think
)
because it was necessary.

Here is an excerpt from the agressive book, The UNIX-Haters :

"C++ users, alas, are forced to pick up their garbage manually. Many
have
been brainwashed into thinking that somehow this is more efficient than
using something written by experts especially for the platform they
use.
These same people probably prefer to create disk files by asking for
platter, track, and sector numbers instead of by name.
...a study comparing performance of programmer-optimized memory
management
techniques in C versus using a standard garbage collector.
C programmers get significantly worse performance by rolling their own.

OK, suppose you are one of those enlightened C++ programmers who wants
a garbage collector portable and reusable..."


I think they are wrong : I disagree with the idea a GC is always
useful. I think it is rarely necessary.

I looked at Boehm's GC examples but they are few.
Up to now I've never used GC, and I would be happy to study simple
examples.

Best regards

Fabrice
 

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