[Gc] Ignoring certain pointers in C++?
Johann 'Myrkraverk' Oskarsson
myrkraverk at yahoo.com
Fri Apr 20 09:07:42 PDT 2007
Bruce Hoult <br... at hoult.org> writes:
> On 4/20/07, Johann 'Myrkraverk' Oskarsson <myrkraverk at yahoo.com> wrote:
>> I'll admit that I'm mostly playing with Gc, or plain using it by
>> deriving from the gc class.
>> Now, in order not to have duplicates of a certain type of object I
>> constructed an object factory that returns a pointer to an already
>> existing one, if it's already been allocated with those parameters.
>> For this I hold a list of all objects of this kind, so they are
>> perpetual. Is it possible to tell Gc not to check this pointer
>> collection when collecting? I'm currently using a link list for these
>> pointers, so I would need to be notified when an object is reclaimed
>> if I keep that structure.
> register_disappearing_link is probably the way to go for this. Just
> make sure that your pointer collection does something sensible when it
> finds that what used to be a pointer to an object is now null -- e.g.
> deletes the linked list node.
I played with it, and tried to be sure my code handles it, but I'm not
at all too sure how I test it. I'm currently using
GC_register_disappearing_link() but according to gc.h, it's better to
use GC_general_register_disappearing_link(); however, it says:
/* Obj must be a pointer to the first word of an object */
/* we allocated. It is unsafe to explicitly deallocate */
/* the object containing link. Explicitly deallocating */
/* obj may or may not cause link to eventually be */
/* cleared. */
So, while I can pretty easily "fake" the circumstances by deleting the
object and clearing the link, I have not managed to come up with a
scenario where the Gc actually reclaims an object and therefore
convince myself that the method is sound.
Yes, I know it's not unusual for small test applications not to have
any GCing taking place, but does anyone have or know of a scenario I
More information about the Gc