Actually I used return_range with element type of unsigned short. Python interprets the element as int.
You mean it is not difficult to wrap a function that returns vector<boost::shared_ptr<char>> then? OK. Then the C++ class needs to take care of the memory when using return_range. I am still a newbie in boost python. I am learning and making progress. I hope I could write new call policies in the future like you did for py++.:) Thanks. On Wed, Dec 17, 2008 at 11:32 PM, Roman Yakovenko <roman.yakove...@gmail.com > wrote: > 2008/12/18 lin yun <yunli...@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/ > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig >
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig