469,612 Members | 2,163 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

does anyone have parent_ptr?

I'd like to know if anyone had some sort of code like parent_ptr that I
could use. Let me just describe what I'm looking for. It's kinda a hybrid
between auto_ptr, and shared_ptr. You can specify who is the parent of the
object pointed to. Then, only the parent object can give someone the
parent-ship, and it itself relinquishes ownership, so only when the
parent_ptr which is a parent dies, will the memory be released.

-Dhruv.


Jul 19 '05 #1
5 1646

"Dhruv" <dh*******@gmx.net> wrote in message news:pa****************************@gmx.net...
I'd like to know if anyone had some sort of code like parent_ptr that I
could use. Let me just describe what I'm looking for. It's kinda a hybrid
between auto_ptr, and shared_ptr. You can specify who is the parent of the
object pointed to. Then, only the parent object can give someone the
parent-ship, and it itself relinquishes ownership, so only when the
parent_ptr which is a parent dies, will the memory be released.


You've lost me...how does this object know when teh parent dies?
Jul 19 '05 #2

"Dhruv" <dh*******@gmx.net> wrote in message
news:pa****************************@gmx.net...
I'd like to know if anyone had some sort of code like parent_ptr that I
could use. Let me just describe what I'm looking for. It's kinda a hybrid
between auto_ptr, and shared_ptr. You can specify who is the parent of the
object pointed to. Then, only the parent object can give someone the
parent-ship, and it itself relinquishes ownership, so only when the
parent_ptr which is a parent dies, will the memory be released.

-Dhruv.


hey there,

If the main requirement of the relationship is that the child dies after the
parent does, then you'd probably be better off maintaining a child-list.
Each parent would have a list of children. When it dies, it deletes all its
children or sends a message to the child telling it to delete itself.

Of course, in addition to this, each child could contain a pointer to its
parent, but that would really only be used for ID purposes.

Yamin
Jul 19 '05 #3

"Dhruv" <dh*******@gmx.net> wrote in message
news:pa****************************@gmx.net...
I'd like to know if anyone had some sort of code like parent_ptr that I
could use. Let me just describe what I'm looking for. It's kinda a hybrid
between auto_ptr, and shared_ptr. You can specify who is the parent of the
object pointed to. Then, only the parent object can give someone the
parent-ship, and it itself relinquishes ownership, so only when the
parent_ptr which is a parent dies, will the memory be released.

-Dhruv.


That wouldn't work. The parent needs to delete the child (preferably in
it's destructor).

What would the child have as the pointer's type? And how would it use that
pointer to know that the parent has died?

If you want to "pass around" the child, you can simply tell parent#2 to
point ot the child object pointed to by parent#1, then tell parent#1 to set
its pointer to NULL. Then, when parent#2 gets destroyed, it will destroy
the chil because it has a valid pointer to it (and parent#1 doesn't).

Howard
Jul 19 '05 #4
On Thu, 03 Jul 2003 23:14:50 +0500, Dhruv wrote:

To all who have asked me about when the parent dies......

Ok, it's something like this. If the parent dies, then ONLY will the
memory be released. The parent need not ensure that it's children are
dead/alive/etc............

So, that means that if a chile and parent have the same pointer, then the
parent dies. It means that the child will be left pointing to a deleted
object. This sounds stupid, but that's what I require.
-Dhruv.


Jul 19 '05 #5
On Thu, 03 Jul 2003 23:14:50 +0500, "Dhruv" <dh*******@gmx.net> wrote:
I'd like to know if anyone had some sort of code like parent_ptr that I
could use. Let me just describe what I'm looking for. It's kinda a hybrid
between auto_ptr, and shared_ptr. You can specify who is the parent of the
object pointed to. Then, only the parent object can give someone the
parent-ship, and it itself relinquishes ownership, so only when the
parent_ptr which is a parent dies, will the memory be released.


I think you could do something like this with boost's weak_ptr. The
real owners of an object have shared_ptrs to it, and things that don't
want to extend the objects life hold weak_ptrs. However, you can't
pass around ownership - shared_ptrs are owners and weak_ptrs aren't.

Tom
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by lawrence | last post: by
2 posts views Thread by Brent Taylor via AccessMonster.com | last post: by
3 posts views Thread by Mephistopheles | last post: by
2 posts views Thread by Bruno Alexandre | last post: by
29 posts views Thread by Vol | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.