Re: Garbage collection
- From: "Chris Thomasson" <cristom@xxxxxxxxxxx>
- Date: Sat, 26 Apr 2008 11:23:56 -0700
"Bartc" <bc@xxxxxxxxxx> wrote in message news:Z%tQj.15440$yD2.11636@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
"jacob navia" <jacob@xxxxxxxxxx> wrote in message news:fusi33$e0n$1@xxxxxxxxxxx
In an interviw with Dr Dobbs, Paul Jansen explains which languages are gaining in popularity and which not:
<quote>
DDJ: Which languages seem to be losing ground?
PJ: C and C++ are definitely losing ground. There is a simple explanation for this. Languages without automated garbage collection are getting out of fashion. The chance of running into all kinds of memory problems is gradually outweighing the performance penalty you have to pay for garbage collection.
<end quote>
lcc-win has been distributing a GC since 2004.
I've little idea about GC or how it works (not about strategies and things but how it knows what goes on in the program).
What happens in this code fragment:
void fn(void) {
int *p = malloc(1236);
}
when p goes out of scope? (Presumably some replacement for malloc() is used.)
A compiler can optmize this away. Even if you did:
extern fne(void* const);
void fn(void) {
void* const buf1 = malloc(1236);
if (buf1) {
void* const buf2 = malloc(1236);
if (buf2) {
L1: fne(buf1);
L2: fne(buf2);
}
}
}
If compiler can detect that 'fne()' does not cache a pointer somewhere, it can possibly detect that 'buf1' goes out of scope at 'L2'. The GC would need to run a cycle to act on this information. It would be nice if a compiler could inject calls to free:
void fn(void) {
void* const buf1 = malloc(1236);
if (buf1) {
void* const buf2 = malloc(1236);
if (buf2) {
L1: fne(buf1);
Inject: free(buf1);
L2: fne(buf2);
Inject: free(buf2);
}
}
}
And the compiler creates a new file, and I can inspect the calls to free to see if the compiler did a good job before I compile it. Would that be feasible?
What about a linked list when it's no longer needed? How does GC know that, do you tell it? And it knows where all the pointers in each node are. I can think of a dozen ways to confuse a GC so it all sounds like magic to me, if it works.
Some GC implementations that will actually scan the stack of all application threads for pointers into its managed heaps, and attempt to follow all the links to NULL. If there are no global pointers to an object and no local pointers in any threads stack, well, it means that its has been rendered into a persistent quiescent state.
.
- Follow-Ups:
- Re: Garbage collection
- From: Chris Thomasson
- Re: Garbage collection
- References:
- Garbage collection
- From: jacob navia
- Re: Garbage collection
- From: Bartc
- Garbage collection
- Prev by Date: Re: Collatz Conjecture
- Next by Date: WebGoo 4.0.0
- Previous by thread: Re: Garbage collection
- Next by thread: Re: Garbage collection
- Index(es):
Relevant Pages
|