[C++-sig] Lifetime of Python object for a pointer argument

David Abrahams david.abrahams at rcn.com
Sat Feb 16 17:54:14 CET 2002


----- Original Message -----
From: "Achim Domma" <achim.domma at syynx.de>
To: <c++-sig at python.org>
Sent: Saturday, February 16, 2002 11:14 AM
Subject: RE: [C++-sig] Lifetime of Python object for a pointer argument


> Hi,
>
> I'm also not an expert, so hopefully Dave will correct my if I'm wrong. As
> far as I know it's in general not an good idea to pass objekts as pointers
> in the current version of boost.python, so you should prefer passing
> parameters by value.

You can pass them, but it's usually a bad idea to hang onto them since as
Min's code demonstrates, there's no way of managing the lifetime of the
referent. Returning pointers is even more problematic.

Smart pointers provide the information you need to manage things properly if
you need reference semantics.


> > // C++ part
> > class grid
> > {
> > public:
> >    grid() { ... }
> >    ...
> > };
>
> Do you allocate dynamic memory in grid ? If yes, is the copy-constructor
> implemented ?

It was my first instinct to ask about that, too, but I don't think that's
his problem.

-Dave





More information about the Cplusplus-sig mailing list