[C++-sig] Boost.Python : Return std::string by ref?

Brian O'Kennedy brian.o'kennedy at vicon.com
Thu May 15 13:11:22 CEST 2008


I'm aware that the std::string reference got copied into an immutable
Python string which is the behaviour I wanted. I'm not intending to try
and in-place modify a string, which is the reason the reference was

The reason the c++ code returns the string by const reference is purely
for performance in c++ code where these classes are mostly used. 

The usage of these classes in Python will require the copying of the
std::string reference into a Python string which is immutable. 

Cheers, Brian

-----Original Message-----
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of Stefan Seefeld
Sent: 15 May 2008 11:50
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Boost.Python : Return std::string by ref?


Brian O'Kennedy wrote:
> Hi Hans,
> Thanks for that, exactly what I wanted! I should have RTFA... :)

Are you sure it really does what you think it does ?

In Python strings are immutable, so there is little sense (other than 
performance) wanting to pass strings by reference. You can't modify them

anyway. What observation makes you believe the string hasn't got copied 
in python ?



      ...ich hab' noch einen Koffer in Berlin...

C++-sig mailing list
C++-sig at python.org

This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system.

More information about the Cplusplus-sig mailing list