473,796 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Garbage collection in C

Tired of chasing free(tm) bugs?

Get serious about C and use lcc-win32. The garbage collector designed by Boehm is the best of its
class. Very simple:

#define malloc GC_malloc
#define free(a) (a=NULL)

NICE isn't it?

No more chasing free() bugs, no more this incredible tedious accounting where it is SO easy to miss
some pointer. Leave to the machine what the machine does best: the boring accounting work and
concentrate in your algorithm, the thing humans do best and where machines fail.

Garbage collection is not restricted to Java or C#. Lcc-win32 introduced it more than 2 years ago in
the context of a Windows C implementation. A DLL you link with your program, a header file more, and
MANY hours of debugging less.

And this code is portable, since Boehm's work runs in many Unices, workstations and many types of
machines.

Garbage collection means less headaches for you, and simpler programs to maintain and debug. The
amount of buggy code that is dedicated to manage the allocation system can be significant and it is
by experience one of the most difficults part to debug.

Scrap it!

http://www.cs.virginia.edu/~lcc-win32

jacob


Nov 13 '05
55 4181
>Tired of chasing free(tm) bugs?

Get serious about C and use lcc-win32. The garbage collector designed by
Boehm is the best of its
class. Very simple:

#define malloc GC_malloc
#define free(a) (a=NULL)

NICE isn't it?


Does it correctly NOT free structures when pointers to them are
stored in a file, and later read back and used (during the same
execution of the program)? I believe this is allowed under ANSI C
and should not yield undefined behavior.

Gordon L. Burditt
Nov 13 '05 #11
jacob navia wrote:
.... snip ...
Garbage collection improves the programming in C, and simplifies
system construction. No longer is it necessary to keep an
error-prone accounting of each memory block you see?

This sounds like an hyperbole because it sounds immedately so
good that it looks exaggerated. But it is not. It is really
better.


You miss the point. The subject here is **portable** C
programming. Anything that is not portable to any compliant C90
or C99 (or even K&R) C compiler is OFF-TOPIC. Code written for
your extensions is highly non-portable, in fact it will not even
function on Windows with other compilers.

Now consider the following erroneous code, written assuming your
GC is in effect:

#define FREE(x) (x = NULL) /* your recommendation, I believe */

p = malloc(n * sizeof *p);
q = p;
/* use p and q */
FREE(p);
/* code using q */
FREE(q);

and failures in "code using q" are going to occur dependant on
when the GC system gets around to actually freeing p. With a
proper free of p ANY further use of q may trigger a run time error
on good quality systems - at any rate the action is probably
repeatable. A free of q should certainly trigger an error.

Now consider something like:

p = malloc(n * sizeof *p);
....
p++;
.... /* does the memory get destroyed in here? */
p--;
free(p);

which I believe to be completely valid C coding.

In addition your messages have excessive line length. No line
should exceed 80 characters, and 65 is much better.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 13 '05 #12
"jacob navia" <ja*********@ja cob.remcomp.fr> wrote:
# Tired of chasing free(tm) bugs?
#
# Get serious about C and use lcc-win32. The garbage collector designed by Boehm is the best of its
# class. Very simple:

As Boehm's code explains, it doesn't work on some programs (which disguise their
pointers).

--
Derk Gwen http://derkgwen.250free.com/html/index.html
The little stoner's got a point.
Nov 13 '05 #13

"Gordon Burditt" <go***********@ sneaky.lerctr.o rg> wrote in message
news:bh******** @library1.airne ws.net...
Tired of chasing free(tm) bugs?

Get serious about C and use lcc-win32. The garbage collector designed by
Boehm is the best of its
class. Very simple:

#define malloc GC_malloc
#define free(a) (a=NULL)

NICE isn't it?


Does it correctly NOT free structures when pointers to them are
stored in a file, and later read back and used (during the same
execution of the program)? I believe this is allowed under ANSI C
and should not yield undefined behavior.

No.

If you have no pointers in RAM to an object it will be freed.

This is definitely NOT an application for a GC. The same if you
store pointers under the operating system control, like storing
pointers in the window extra bytes, under win32. Those objects
will not be visible to the GC and will be freed.
Nov 13 '05 #14

"CBFalconer " <cb********@yah oo.com> wrote in message news:3F******** *******@yahoo.c om...
jacob navia wrote:
... snip ...

Garbage collection improves the programming in C, and simplifies
system construction. No longer is it necessary to keep an
error-prone accounting of each memory block you see?

This sounds like an hyperbole because it sounds immedately so
good that it looks exaggerated. But it is not. It is really
better.


You miss the point. The subject here is **portable** C
programming.


I repeat:
The work of Mr Boehm has been ported to windows, linux, and sun, among many others.
It is perfectly portable code in the greate majority of cases.
Anything that is not portable to any compliant C90
or C99 (or even K&R) C compiler is OFF-TOPIC.
Ok. We then go to the seventies. Ahhh what a big time then...
Code written for
your extensions is highly non-portable, in fact it will not even
function on Windows with other compilers.

Yes. No other C compiler under windows features a GC as standard environment.
But you can use the GC dll with code compiled by ANY windows compiler. Just
load the library (gc.dll) and you are done.
Now consider the following erroneous code, written assuming your
GC is in effect:

#define FREE(x) (x = NULL) /* your recommendation, I believe */

p = malloc(n * sizeof *p);
q = p;
/* use p and q */
FREE(p);
/* code using q */
FREE(q);

and failures in "code using q" are going to occur dependant on
when the GC system gets around to actually freeing p.
Yes. The same behavior as free().
With a
proper free of p ANY further use of q may trigger a run time error
on good quality systems - at any rate the action is probably
repeatable.
If free() destroys the data contained in the memory block, filling it
with data designed to provoke traps you MAY get an error if the
data contained pointers. Maybe you get bad results, that is all. The
same behavior as the gc.

A free of q should certainly trigger an error. On many systems freeing an object twice will provoke corruption of the
malloc system.
Now consider something like:

p = malloc(n * sizeof *p);
....
p++;
.... /* does the memory get destroyed in here? */
NO, since there is a pointer to the inner part of the object
p--;
free(p);

which I believe to be completely valid C coding.

It is
In addition your messages have excessive line length. No line
should exceed 80 characters, and 65 is much better.


Yes, I know. We are in the seventies and your terminal is an IBM3270.

Nov 13 '05 #15


Arthur J. O'Dwyer wrote:
and say, "Aha! Your problem must be with either 'mystruct' or
'mystruct->name'!" because the actual problem might be three
translation units away, in the line

pork = NULL;

and it simply happens that the GC has finally gotten around to
deleting 'pork', and has caused an error in the process (perhaps
the contents of '*pork' contain a pointer to 'mystruct', and
somewhere earlier the GC lost track of the reference count,
so that freeing 'pork' frees 'mystruct' unintentionally ; maybe
something else happens).


In regard to this comment only, what you said cannot happen. If contents
of *pork contain a pointer to mystruct then the GC will not under any
circumstances decide to delete pork, at least not Bacon's Refernce
counting algorithm. Circular references are not a problem in many modern
ref-count GCs, namely Jikes RVM's JMTk (Jikes Memory management Toolkit).

-Andre

Nov 13 '05 #16
On Sun, 10 Aug 2003 10:34:43 +0200, "jacob navia"
<ja*********@ja cob.remcomp.fr> wrote:
Garbage collection is not restricted to Java or C#. Lcc-win32 introduced it more than 2 years ago in
the context of a Windows C implementation.


Where did you get the idea that garbage collection was invented two
years ago by Lcc-win32? Garbage collection was invented many years
before Java, C# or Windows existed.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 13 '05 #17
On Mon, 11 Aug 2003 02:22:38 +0200, "jacob navia"
<ja*********@ja cob.remcomp.fr> wrote:

and wrote, and wrote, and ...

I ignored the advertising the first time, but I am now very close to
filtering your messages as a continuing waste of my time and disk
space. I suggest you start your own newsgroup.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 13 '05 #18
In article <bh**********@n ews-reader4.wanadoo .fr>, jacob navia wrote:

Yes, I know. We are in the seventies and your terminal is an IBM3270.

I don't know about his terminal, but I read news in an 80x25 xterm. And
have many xterms on several virtual desktops. An I get really annoyed
when I have to resize one of the just to read news. I read your postings
(scrolling left and right) just because of your name. If somebody else
posted an article with too long lines, I'd just ignore his post. And
so would many other people.

Nov 13 '05 #19

"Alan Balmer" <al******@att.n et> wrote in message news:jp******** *************** *********@4ax.c om...
On Mon, 11 Aug 2003 02:22:38 +0200, "jacob navia"
<ja*********@ja cob.remcomp.fr> wrote:

and wrote, and wrote, and ...

I ignored the advertising the first time, but I am now very close to
filtering your messages as a continuing waste of my time and disk
space.


Please do so.

Your message is so constructive and full real arguments, that I think
it is better to ignore it.

comp.lang.c according to you, is designed to answer questions like

HELP HELP!!!

I wrote
p[i++] = ++i;

and it doesn't work.

Serious discussions that go beyond the usual newbee questions should
go elsewhere. Obviously.

jacob

Nov 13 '05 #20

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

Similar topics

1
2338
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and then throws them away and then monitors the garbage collection and store statistics on it, preferably in C#. I want to know what is the longest period of time that an application may lock up while garbage collection is processing. Thanks!
6
810
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
11
2737
by: Rick | last post by:
Hi, My question is.. if Lisp, a 40 year old language supports garbage collection, why didn't the authors of C++ choose garbage collection for this language? Are there fundamental reasons behind this? Is it because C is generally a 'low level' language and they didn't want garbage collection to creep into C++ and ruin everything? Just wondering :)
34
6435
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple, probably a few hundred lines of code in Python. There is a need to interact with network using the socket module, and then probably a need to do something hardware- related which will get its own driver written in C.
5
3614
by: Bob lazarchik | last post by:
Hello: We are considering developing a time critical system in C#. Our tool used in Semiconductor production and we need to be able to take meaurements at precise 10.0 ms intervals( 1000 measurement exactly 10 ms apart. In the future this may decrease to 5ms ). I am concerned that if garbage collection invokes during this time it may interfere with our measurement results. I have looked over the garbage collection mechanism and see no...
8
3047
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by the mainline. The class that instantiated the object in question is definitely still in existence at the point garbage collection swoops in and yanks it out from under my processing. Is there a way to ensure an instantiated object cannot be freed...
28
3189
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...
56
3716
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()
350
11907
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use one, and in what percentage of your projects is one used? I have never used one in personal or professional C++ programming. Am I a holdover to days gone by?
158
7909
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
9683
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
9529
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
10457
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...
1
10176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
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...
0
9054
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5443
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...
1
4119
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
2
3733
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.