I\'m facing a design issue in my program. I have to manage Nodes object which are part of a root ChainDescriptor.
Basically it looks like the following:
You can use shared_ptr
for m_childs
and weak_ptr
for m_parent
.
However, it might be still reasonable to retain the raw pointer to the parent Node
and don't use any weak pointers at all. The safeguarding mechanism behind this is the invariant that non-null parent always exists.
Another option is using shared_ptr
in ChainDescriptor
only and retaining all raw pointers in Node
. This approach avoids weak pointers and has a clean ownership policy (parent nodes own their children).
Weak pointers will help you to manage the memory automatically, but the backside of this are fuzzy ownership logic and performance penalties.