[PyQt] Python and smartpointers
Arve Knudsen
arve.knudsen at gmail.com
Thu Aug 7 13:10:56 BST 2008
I'm dealing with the problem of C++ reference counting again, so I
want to come up with a solution to this problem once and for all. Does
anyone have a good pattern for wrapping C++ smartpointers with SIP?
Thanks,
Arve
On Fri, Jun 13, 2008 at 3:33 PM, Giovanni Bajo <rasky at develer.com> wrote:
> On 6/13/2008 3:16 PM, Arve Knudsen wrote:
>
>> In our C++ application we typically use smartpointers to manage
>> pointers automatically, but there's the problem of transferring such
>> objects to Python. What I'd like to do is pass smartpointers to
>> Python, so that one plays along with the C++ memory management scheme,
>> but treat these as their managed objects (i.e., not having to worry
>> about the presence of smartpointers). Is there a typical pattern for
>> accomplishing this, or should I go about it completely differently?
>
> One idea that comes to mind is to increment the smart-pointer counter when
> the Python wrapper is created and decrement it when the Python wrapper is
> destroyed. This would allow the Python code to keep the object in life by
> itself, even though the Python refcount would of course be different from
> the C++ refcount.
>
> I have no idea how to implement this with SIP though; maybe Phil will chime
> in.
> --
> Giovanni Bajo
> Develer S.r.l.
> http://www.develer.com
>
More information about the PyQt
mailing list