473,847 Members | 1,489 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 2164

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
2059
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
2121
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, SqlDataAdapter etc. objects, so I thought I'd create a class with a bunch of factory methods to create my classes for me. But, I'm unclear about how garbage collection works, and if it is safe to do this. It seems to compile, but am I asking for...
13
3824
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 can manage resources as well as objects. The programming style is clear and easy, conforming to RAII (Resource Acquisition Is Initialization) idiom of C++ programmers. The memory usage is very efficient, acyclic garbage is
28
3198
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 this work be library based or language based and will it be based on that of managed C++? Then of course there are the finer technical questions raised (especially due to pointer abuse). Is a GC for C++ just a pipe dream or is there a lot of work...
142
6892
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 chunks and recycles them. This memory allocation strategy has been adapted to C (and C++) by the library written by Hans J Boehm and Alan J Demers. Why a Garbage Collector? -----------------------
8
1803
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 down. I must point out that a heck of a lot of data are being read in and manipulated, and I was wondering if there were any metrics to show much of a performance hit is occurring during the initialisation? If it turns out that the GC is having a...
56
3731
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 = null; Private Microsoft.Office.Interop.Outlook.NameSpace _Namespace = null; The Constructor: public OutlookObject()
46
2201
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, and auto_ptrs, gurus suggest that may be better to use a reference-counted smart pointer, or a garbage-collector. But in which cases it is better to use one technique and in which cases another? IOW, which is the design criterion?
158
7939
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 discouraged due to some specific reason. If someone can give inputs on the same, it will be of great help. Regards, Pushpa
0
9892
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9734
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10991
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10347
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7888
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7061
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5725
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4540
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 we have to send another system

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.