Thread overview
Question about using class refs as AA keys
Dec 30, 2004
Walter
December 30, 2004
Is it safe to do something like this?

Class Node
{
protected:
    static Node[Node] nodes;
public:
    this()
    {
        nodes[this]=this;
    }
    ~this()
    {
        delete nodes[this];
    }
}

I don't know how the GC works, but is this safe?  I'm just wondering if the class references will change, causing the key to become invalid when the GC is run.  Or are the class refs doubly indirected, making it safe?


December 30, 2004
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:cr19ka$q75$1@digitaldaemon.com...
> Is it safe to do something like this?
>
> Class Node
> {
> protected:
>     static Node[Node] nodes;
> public:
>     this()
>     {
>         nodes[this]=this;
>     }
>     ~this()
>     {
>         delete nodes[this];
>     }
> }
>
> I don't know how the GC works, but is this safe?  I'm just wondering if
the
> class references will change, causing the key to become invalid when the
GC
> is run.  Or are the class refs doubly indirected, making it safe?

Yes, it's safe to do it!


December 30, 2004
> Yes, it's safe to do it!

Sweet :)