c++-sig@python.org
[Top] [All Lists]

Re: [C++-sig] how to handle bare references with a shared_ptr HeldType

Subject: Re: [C++-sig] how to handle bare references with a shared_ptr HeldType
From: Hans Meine
Date: Thu, 22 Sep 2005 00:34:47 +0200
On Thursday 22 September 2005 00:20, Gregory Price wrote:
> class A {
>     // ... lots of stuff ...
> };
>
> class B {
>     shared_ptr<A> a;
> public:
>     A& getA() { return *a; };
> };
> """
>
> I'm exposing A with a HeldType of shared_ptr<A>.
>
> [...]
> I could use copy_non_const_reference to make a
> new copy of the A instance.  That'd be safe,
> but A instances are big and I'd rather not copy them.

Hmm.  What about return_internal_reference (which I am using a lot)?
AFAICS, the C++ A object will not be deleted as long as B is not deleted,  
because of the shared ptr.  OTOH, during the lifetime of the A python 
wrapper, B will not get deleted because of the custodian-ward relationship 
initialized via return_internal_reference.  Does that make sense?

-- 
Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
_______________________________________________
C++-sig mailing list
C++-sig@xxxxxxxxxx
http://mail.python.org/mailman/listinfo/c++-sig

<Prev in Thread] Current Thread [Next in Thread>