Garbage Collection Idea
Sean Kelly
sean at f4.ca
Fri Jun 2 10:12:49 PDT 2006
Craig Black wrote:
>
>> Another potential problem is this:
>>
>> # class Foo { ... }
>> # Foo bar = new Foo;
>> # void* quxx = cast(void*)bar;
>>
>> What happens now? We can no longer tell what type of memory is pointed
>> to by quxx, but we *still* need to scan it. The only way I can think of
>> to solve this would be to mark each segment of memory with the kind of
>> allocation (class, struct or otherwise), and what the type is. That, or
>> you can just revert to blind scanning, but then it's no better than the
>> default GC (and more complex code-wise).
>
> I didn't initially consider this case, but it wouldn't be to hard to
> accomodate it. Each allocation unit, whether it is a class instance or not,
> would have to get an id that describes its identity.
char** c = cast(char**) malloc( HEIGHT );
memset( c, 0, HEIGHT );
gc_addRange( c, c + HEIGHT );
Where would this identity data go? Another example:
class C {
int val;
}
int* p;
{
C c = new C;
p = &c.val;
}
The instance of C must be kept alive because there is a reference to
it... but to a member element, not the root of the object.
Sean
More information about the Digitalmars-d
mailing list