[Trilinos-Users] create RCP for member of an RCP-owned class

Bartlett, Roscoe A. bartlettra at ornl.gov
Fri Oct 14 12:50:58 MDT 2011


Holger,

What you need to use is the "object self reference" idiom described in Section5.13.3 in:

    http://www.cs.sandia.gov/~rabartl/TeuchosMemoryManagementSAND.pdf

The issue is that an object can not hold a strong RCP to itself it will never get deleted.   Instead, you need to create a strong owning RCP when you give up an external view of the internally held object is requested.

Let me know if you have any questions.  If you can't figure it out, I can provide code that shows this to you.

Cheers,

-Ross


> -----Original Message-----
> From: trilinos-users-bounces at software.sandia.gov [mailto:trilinos-users-
> bounces at software.sandia.gov] On Behalf Of Holger Brandsmeier
> Sent: Friday, October 14, 2011 2:37 PM
> To: trilinos-users at software.sandia.gov
> Subject: [Trilinos-Users] create RCP for member of an RCP-owned class
> 
> Dear list,
> 
> given a class A, that is owned by an RCP, say by a variable a of type
> RCP<A>. A has a member `list` of type Teuchos::Array<T>. Now I want to
> generate an RCP< Teuchos::Array<T> > where the deallocator is tied to
> the RCP of the object. This will ensure that A is only deleted when
> the use counts for both RCPs reach zero.
> 
> Which is the recommended way of doing this? Do I need to write my own
> deallocated class for this, or is there already something existing
> inside Teuchos?
> 
> Thanks,
> Holger
> 
> _______________________________________________
> Trilinos-Users mailing list
> Trilinos-Users at software.sandia.gov
> hxxp://software.sandia.gov/mailman/listinfo/trilinos-users





More information about the Trilinos-Users mailing list