G
Gordon Burditt
Yes , I know that of course. But I was commenting on the fact
I claim that any real implementation of garbage collection for C
(the implementation NEED NOT be portable) has at least one of three
(fatal) problems:
(1) It never frees anything, in which case it can't be called garbage
collection.
(2) It frees stuff when it shouldn't. In particular, it doesn't
deal properly with pointers stored in files (and read back and used
later by the same invocation of the program) or encrypted pointers
stored in files, or encrypted pointers stored in memory.
(3) It uses excessive resources during garbage collection.
(Yes, this is subjective, but I classify reading whole hundred-terabyte
files looking for pointers that aren't there as excessive.)
C already has (1).
(2) is not an issue for at least 99.99% of real programs, but it
does introduce problems doing something that ANSI C says is acceptable.
(3) is likely caused by trying to fix (2).
This is true if a number of things available from third-party
libraries are substituted for GC: say, networking, graphics, database
access, etc.
I have grave doubts that it is possible to write a practical GC
system for C that doesn't have at least one of the problems listed
above. That business about allowing pointers in files makes it
really hard.
My standard for C + GC: take the ANSI C standard, and add a statement
that a program may malloc() memory without freeing it, memory that
no longer has any reference to it anywhere is freed automatically
(eventually), putting off running out of resources. Anything that
doesn't cause Undefined Behavior in plain ANSI C shouldn't cause
it in C + GC.
Perhaps it could require that the program:
#include <stdlib.h>
int main(void) {
char *p;
while (1) {
p = malloc(1);
}
}
shouldn't ever run out of memory.
I'm not going to require that the IMPLEMENTATION of GC be written
in portable C (the implementation of fopen() needn't be portable
either). It won't help.
Gordon L. Burditt
I claim that any real implementation of garbage collection for C
(the implementation NEED NOT be portable) has at least one of three
(fatal) problems:
(1) It never frees anything, in which case it can't be called garbage
collection.
(2) It frees stuff when it shouldn't. In particular, it doesn't
deal properly with pointers stored in files (and read back and used
later by the same invocation of the program) or encrypted pointers
stored in files, or encrypted pointers stored in memory.
(3) It uses excessive resources during garbage collection.
(Yes, this is subjective, but I classify reading whole hundred-terabyte
files looking for pointers that aren't there as excessive.)
C already has (1).
(2) is not an issue for at least 99.99% of real programs, but it
does introduce problems doing something that ANSI C says is acceptable.
(3) is likely caused by trying to fix (2).
Why do you insist on being obtuse? Use of GC in a portable C
program is bad, unless the complete GC system is written in
portable C and published as part of that program. Otherwise the
program becomes non-portable.
This is true if a number of things available from third-party
libraries are substituted for GC: say, networking, graphics, database
access, etc.
However, I have grave doubts that it is possible to write a
completely portable GC system.
I have grave doubts that it is possible to write a practical GC
system for C that doesn't have at least one of the problems listed
above. That business about allowing pointers in files makes it
really hard.
My standard for C + GC: take the ANSI C standard, and add a statement
that a program may malloc() memory without freeing it, memory that
no longer has any reference to it anywhere is freed automatically
(eventually), putting off running out of resources. Anything that
doesn't cause Undefined Behavior in plain ANSI C shouldn't cause
it in C + GC.
Perhaps it could require that the program:
#include <stdlib.h>
int main(void) {
char *p;
while (1) {
p = malloc(1);
}
}
shouldn't ever run out of memory.
Remember, this implies making no
assumptions other than those stated in the C standard. For
example, there is no way of scanning all memory in use for any
particular value.
I'm not going to require that the IMPLEMENTATION of GC be written
in portable C (the implementation of fopen() needn't be portable
either). It won't help.
Gordon L. Burditt