473,507 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Garbage Collector examples ?

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

Oct 28 '06 #1
3 2145

Fab wrote:
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/Resourc...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!!

Oct 28 '06 #2
Salt_Peter wrote:
>
Fab wrote:
>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/Resourc...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
Oct 28 '06 #3
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

Oct 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2006
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
2
2105
by: C P | last post by:
I'm coming from Delphi where I have to explicitly create and destroy instances of objects. I've been working through a C#/ASP.NET book, and many of the examples repeat the same SqlConnection,...
13
3772
by: Mingnan G. | last post by:
Hello everyone. I have written a garbage collector for standard C++ application. It has following main features. 1) Deterministic Finalization Providing deterministic finalization, the system...
28
3132
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
142
6692
by: jacob navia | last post by:
Abstract -------- Garbage collection is a method of managing memory by using a "collector" library. Periodically, or triggered by an allocation request, the collector looks for unused memory...
8
1773
by: Paul.Lee.1971 | last post by:
Hi everyone, A program that I'm helping to code seems to slow down drastically during initialisation, and looking at the profiling graph, it seems to be the garbage collector thats slowing things...
56
3620
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
46
2132
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
158
7690
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.