Differences between revisions 2 and 4 (spanning 2 versions)
Revision 2 as of 2002-11-16 11:56:41
Size: 915
Editor: pD9530A09
Comment:
Revision 4 as of 2002-12-28 01:54:23
Size: 921
Editor: MikeRovner
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
`CallPolicy` allows boost.python to deal with raw references and pointers. `CallPolicy` allows ["boost.python"] to deal with raw references and pointers.
Line 36: Line 36:
def("Tfactory", factory, return_value_policy<manage_new_object> ); def("Tfactory", factory, return_value_policy<manage_new_object>() );

CallPolicy allows ["boost.python"] to deal with raw references and pointers. Different policies specifies different strategies of managing object ownership.

TableOfContents

with_custodian_and_ward

ties lifetimes of the arguments

with_custodian_and_ward_postcall

ties lifetimes of the arguments and results

return_internal_reference

ties lifetime of one argument to that of result keep the owning object alive as long as the owned objects are also alive.

return_value_policy<T>

with T one of:

reference_existing_object

naïve (dangerous) approach

copy_non_const_reference

copy_const_reference

Boost.Python v1 approach

manage_new_object

Adopt a pointer and hold the instance

Use case:

T* factory() { return new T(); }

class_<T>("T");

def("Tfactory", factory, return_value_policy<manage_new_object>() );

boost.python/CallPolicy (last edited 2008-11-15 14:01:02 by localhost)

Unable to edit the page? See the FrontPage for instructions.