Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Garbage collection in C

Reply
Thread Tools

Garbage collection in C

 
 
Gordon Burditt
Guest
Posts: n/a
 
      08-11-2003
>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
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      08-11-2003
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 () ()
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
 
 
 
Derk Gwen
Guest
Posts: n/a
 
      08-11-2003
"jacob navia" <> 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.
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      08-11-2003

"Gordon Burditt" <> wrote in message
news:bh6ohr$...
> >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.


 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      08-11-2003

"CBFalconer" <> wrote in message news:...
> 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.



 
Reply With Quote
 
Andre
Guest
Posts: n/a
 
      08-11-2003


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

 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      08-11-2003
On Sun, 10 Aug 2003 10:34:43 +0200, "jacob navia"
<> 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

 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      08-11-2003
On Mon, 11 Aug 2003 02:22:38 +0200, "jacob navia"
<> 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

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      08-11-2003

"Alan Balmer" <> wrote in message news:...
> On Mon, 11 Aug 2003 02:22:38 +0200, "jacob navia"
> <> 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



 
Reply With Quote
 
Zeljko Vrba
Guest
Posts: n/a
 
      08-11-2003
In article <bh7mpk$fom$>, 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Templates - Garbage In Garbage Not Out ramiro_b@yahoo.com C++ 1 07-25-2005 04:48 PM
Garbage Collection kamran MCSD 1 04-04-2005 10:04 PM
Garbage Collection and Manage Code? Laser Lu ASP .Net 5 01-27-2004 03:48 AM
Debbugging help! (.NET 1.1 Framework Garbage Collection Problems) Cheung, Jeffrey Jing-Yen ASP .Net 3 07-10-2003 07:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57