Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > does anyone have parent_ptr?

Reply
Thread Tools

does anyone have parent_ptr?

 
 
Ron Natalie
Guest
Posts: n/a
 
      07-03-2003

"Dhruv" <(E-Mail Removed)> wrote in message news(E-Mail Removed)...
> 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?


 
Reply With Quote
 
 
 
 
Dhruv
Guest
Posts: n/a
 
      07-03-2003
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.






 
Reply With Quote
 
 
 
 
Yamin
Guest
Posts: n/a
 
      07-03-2003

"Dhruv" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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


 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      07-03-2003

"Dhruv" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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


 
Reply With Quote
 
Dhruv
Guest
Posts: n/a
 
      07-04-2003
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.






 
Reply With Quote
 
tom_usenet
Guest
Posts: n/a
 
      07-04-2003
On Thu, 03 Jul 2003 23:14:50 +0500, "Dhruv" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does anyone Know Anyone at Maas Rowe I can talk to channing28270@gmail.com Computer Support 3 07-05-2006 08:27 AM
does anyone here have a problem with using newsgroups on port 119with seamonkey browser / newsreader .. Seamonkey user Firefox 2 11-13-2005 05:41 PM
Samsung SCD6040 - Anyone have one, used one, or have reviews on one? g wills Digital Photography 0 09-08-2004 08:06 PM
Does anyone have the I2C vhdl code and work for Altera Flex10K FPGA? underground VHDL 5 07-22-2004 10:45 PM
does anyone have a cisco pix? Cisco 5 07-07-2004 01:38 PM



Advertisments