Traditionally, the proper solution to avoid deep copies is to wrap a 
std::shared_ptr<std::string> instead of a std::string directly.

If your strings are short of course, it may well be faster to leave 
it as is. std::shared_ptr is not lightweight and may use atomic 
instructions, the bandwidth for which in a system is always limited.

Niall

On 23 Dec 2012 at 16:16, simon zhang wrote:

> ..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 <tallji...@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@python.org
> > http://mail.python.org/**mailman/listinfo/cplusplus-sig<http://mail.python.org/mailman/listinfo/cplusplus-sig>
> >
> 


-- 
Any opinions or advice expressed here do NOT reflect those
of my employer Research In Motion Inc.
Work Portfolio: http://careers.stackoverflow.com/nialldouglas/



Attachment: SMime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to