Invariants and reference counting
Benjamin Thaut
code at benjamin-thaut.de
Wed Dec 28 22:49:09 PST 2011
I implemented a base class for reference couting. The problem now is
that because the RemoveReference function is a public one and might
destroy and delete the object when the reference count drops to 0 the D
invariant handler will crash because it gets called always at the end of
that function. Now I want this function to be public because I might
need to manually add / remove references at some point. Also I want
destruction in there because I don't want to copy the destruction code
in every place I call RemoveReference. Is there even a way to fix this?
Ideas I had so far
1) Make the RemoveReference function private and only allow reference
counting through a smart pointer
2) Make the base class a templated struct which is always the first
member of the class (hacky)
Is there a way to disable invariants globally (compiler switch?).
Because in release mode I don't want the invariant hander to be called
especially since the class does not even use invariants.
Is there a way to disable invariants per class?
--
Kind Regards
Benjamin Thaut
More information about the Digitalmars-d
mailing list