[C++-sig] How to converter std::string* in boost.python?

simon zhang hapopen at gmail.com
Sun Dec 23 09:16:20 CET 2012


..so,It seems I can only convert std::string and make a deep copy.I can
only avoid it as much as possible.Thank you.


2012/12/22 Jim Bosch <talljimbo at gmail.com>

> On 12/21/2012 03:52 AM, simon zhang wrote:
>
>> How to converter std::string* in boost.python?I have to handle some data
>> of c++ in python.The data may be big.So I return a pointer to python.
>> But there are some errors.
>>
>>
> If the data is big, and you really want to avoid a deep copy, the only way
> to use it is if you manually allocate the memory as a Python str object
> using the Python C API or return it as something else (like a NumPy array
> or buffer object, or a custom Boost.Python-wrapped class) that can hold
> C++-allocated memory.  A Python str object always owns its own memory, and
> so does std::string, so you can't convert from one to the other without a
> deep copy.
>
> Jim
>
> ______________________________**_________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/**mailman/listinfo/cplusplus-sig<http://mail.python.org/mailman/listinfo/cplusplus-sig>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20121223/03ef428d/attachment-0001.html>


More information about the Cplusplus-sig mailing list