A question/suggestion regarding the GC

Jarrett Billingsley jarrett.billingsley at gmail.com
Sat Sep 20 15:27:19 PDT 2008


On Sat, Sep 20, 2008 at 4:58 PM, bearophile <bearophileHUGS at lycos.com> wrote:

> Thank you. I don't know if you are trying to be sarcastic, but for me this stuff isn't obvious as it is for most of you here. Anyway, I'm sure that with time I'll understand those topics.

It was sarcasm, but only because I thought you already knew how
conservative GCs worked ;)

> But isn't this impossible? There are dynamic casts too.

Dynamic casts are only made possible by objects carrying around their
type information -- which is determined at compile time -- around with
them.  But even then, there's no need for that to come into
consideration in the GC.  I suppose what you're saying is that if you
have a class Base and a class Derived : Base, and then something else
has a Base reference that's really a Derived instance, that issues
would arise.  Not so -- any object.classinfo will point to the
typeinfo that that object _really_ is, so any instance of Derived,
even if it's stored in a Base reference, will have typeid(Derived) as
its classinfo.  So as long as the typeinfo/classinfo defines some
method or bitmask or whatever for determining what to scan, dynamic
casts don't come into it.

> If you are willing, you may explain me why doing it at runtime may significantly damage the general performance of general D code.

It's pointless to do something at runtime if it can be done perfectly
fine at compile time.  That's the _entire reason that
statically-checkable languages exist_.

> Okay (in some of my programs I use mostly the C heap, so I presume my code is not common).

Your code is, from what I've seen, uncommon.

> But what I have tried to express is that there can be levels of precision, and even if some sources of approximation can't be avoided (or are too much difficult to avoid) there can be ways to remove some other of them. A more precise GC may be better than a less precise one, even if both of them aren't fully precise :-)

True :)

> I hope to see this, but I think there are some people that like D that think that having two different GCs running at the same time is too much complext, etc.

Let me guess: in that sentence, "some people" means "me" (you).

Actually it wouldn't require having 2 GCs at all, as long as you
forewent the possibility of having a moving GC.  More or less SafeD
would be memory-safe, and so this theoretical "almost-precise" GC
_would_ be precise for SafeD code, and would only be imprecise when
dealing with non-SafeD code.  It would all be covered by one GC,
though.

If your _entire_ program were in SafeD, however, you could come up
with a new GC that could do heap compaction and the like.


More information about the Digitalmars-d-learn mailing list