[C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type?
Roman Yakovenko
roman.yakovenko at gmail.com
Thu Dec 18 08:32:51 CET 2008
2008/12/18 lin yun <yunlin07 at gmail.com>:
>> Yes. I believe Py++ deals with boost::shared_ptr without invoking the
>> user. Just use default call policy.
> That's good news! How about vector<boost::shared_ptr<unsigned short *>> ?
No :-(, unsigned short is immutable type. You will have too write
wrapper. Take a look on Py++ - ctypes functionality:
http://language-binding.net/pyplusplus/documentation/ctypes/ctypes_integration.html
>> Can you provide small example of what you are trying to do?
>
> I have a C++ function "imgreader" which reads an image and return a
> "unsigned short *" pointer. I have another piece of Python code that calls
> imgreader and gets the pointer to the image data. Where should I release the
> memory of the image data when it is not needed any more? in python side or
> C++ side?
return_range call policy doesn't manage the memory. It assumes that
the buffer is owned by C++ class.
I guess you should use "as_tuple" call policy, with
memory_managers::delete_ memory manager.
This way you don't need to force user to manage the memory.
May be you will have to create new call policy - hybrid of
return_range and as_tuple:
* efficiency of return_range
* memory management ability of as_tuple
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list