[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-dev] an idea for finalization of C objects
drats. i had a sneaking suspicion you were going to say something like
On 02/12/2004, at 5:37 PM, James McCartney wrote:
On Dec 1, 2004, at 10:07 PM, ccos wrote:
i understand that you cannot have dtors on the sc lang side because
of the possible resurrection of dead objects which would necessitate
a second pass of the gc,
That is not the reason that there is no finalization. The reason is
that SC objects are never explicitly freed. The garbage collector has
no sweep phase, so it never visits freed objects. Adding a sweep phase
would make the GC slower. If you are going to have finalization you
have to have some way to identify which finalizable objects have been
freed this cycle. Without a sweep of the free objects, you don't know.
there is of course the very slight runtime cost of checking if an
object has a finalizer but i'm wondering if there are any other
reasons why this would be a bad idea, or if it just wouldn't be
possible because of something i don't know about the gc?
You'd never know when or what objects to call the finalizer on.
As an example, the SC GC is not a copying collector, but it works like
one. In a copying collector reachable objects are copied from "old"
space into "new" space. When you have copied all reachable objects,
you can then reuse the "old" space. The objects in "old" space are
implicitly free because you never reached them in your scan. You never
touched the free objects so you never had a chance to finalize them.
Adding finalization means adding a mechanism to identify the
finalizable object that were left in "old" space. SC does not have
this mechanism. SC3d5 did have such a mechanism, but it slowed down
--- james mccartney james@xxxxxxxxxxxxxx
SuperCollider - a real time audio synthesis programming language
sc-dev mailing list