C garbage collection -crazy idea

O

onkar

This idea might be vey crazy. But I hope to get answers to this .. from
comp.lang.c

If a compiler is designed such that it automatically adds a free()
matching every malloc()
then is it not a garbage collection (in the first place , garbage will
not be generated !! ) . Is it
possible to have a compiler with such feature. Or if Its not a good
idea (or may be this is an idiotic idea) please tell me why is it so ??
 
B

Barry

onkar said:
This idea might be vey crazy. But I hope to get answers to this .. from
comp.lang.c

If a compiler is designed such that it automatically adds a free()
matching every malloc()
then is it not a garbage collection (in the first place , garbage will
not be generated !! ) . Is it
possible to have a compiler with such feature. Or if Its not a good
idea (or may be this is an idiotic idea) please tell me why is it so ??

The first problem that comes to mind is how would a compiler possibly
know where or when to add the free().
 
M

Malcolm

onkar said:
This idea might be vey crazy. But I hope to get answers to this .. from
comp.lang.c

If a compiler is designed such that it automatically adds a free()
matching every malloc()
then is it not a garbage collection (in the first place , garbage will
not be generated !! ) . Is it
possible to have a compiler with such feature. Or if Its not a good
idea (or may be this is an idiotic idea) please tell me why is it so ??
Garbage collection itself is a good idea. One way of doing it would be to
match mallocs() with free and forbid returning alocated memory from a
function. However this would disallow many useful data structures.
The way most languages do it is to tag areas of memory, and free them when
they finally go out of scope. The disadvantage with this is that the garbage
collection becomes non-trivial, and fairly though not excessively processor
intensive.

Jacob Navia has added garbage collection to C. You might want to check out
his lcc-win compiler (Goggle for his name and lcc-win).

Whether it is a good idea to extend the C language this way is a moot point.
It changes one of the most fundamental characteristics of the language,
which is that every line of C matches to a few simple assembly instructions.
OK some pedant will post a 1024-line of C which is incredibly hard to
hand-compile. But generally the rule holds.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top