Re: Lock-free reference counting
- From: Juha Nieminen <nospam@xxxxxxxxxxxxxx>
- Date: Sun, 23 Nov 2008 15:47:20 GMT
Mark Wooding wrote:
Juha Nieminen <nospam@xxxxxxxxxxxxxx> wrote:[snip]
The only way 'a' would not have a pointer to the allocated object is
if f() nulled (or whatever) that pointer.
Huh? We're discussing code of the form
ptr<foo> a = ...;
f(a);
g();
So you are basically saying that in this hypothetical non-C++ language
what happens there is basically what in C++ would happen if you wrote:
f(ptr<foo>(new Object));
g();
(In other words, the object is created for calling the f() function
only, and destroyed immediately afterwards.)
Or, if we put that in another way:
ptr<foo> a = ...;
f(a);
// At this point the compiler sees that 'a' is not used anymore, so
// it drops it immediately after f() returns;
g();
As someone already put it, this requires compiler support to work. A
GC engine alone cannot know this. Alternatively, it needs to be a
specified language feature:
ptr<foo> a = ...;
f(a);
// 'a' has been "used up" at this point, so the following:
g(a);
// causes an error because 'a' doesn't exist anymore.
In either case I really don't see why reference counting would act any
differently (assuming that the "ptr<>" type was internally reference
counted rather than garbage-collected). Whatever the means to
drop/destroy/forget/nullify/whatever that 'a', a reference-counting
scheme would delete the object when it happens.
.
- Follow-Ups:
- Re: Lock-free reference counting
- From: Mark Wooding
- Re: Lock-free reference counting
- From: Jon Harrop
- Re: Lock-free reference counting
- References:
- Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Jon Harrop
- Re: Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Jon Harrop
- Re: Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Mark Wooding
- Re: Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Mark Wooding
- Lock-free reference counting
- Prev by Date: Re: find polygon
- Next by Date: Re: find polygon
- Previous by thread: Re: Lock-free reference counting
- Next by thread: Re: Lock-free reference counting
- Index(es):