Thread overview | |||||
---|---|---|---|---|---|
|
December 30, 2004 Question about using class refs as AA keys | ||||
---|---|---|---|---|
| ||||
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 Re: Question about using class refs as AA keys | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | "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! |
Copyright © 1999-2021 by the D Language Foundation