I have a Visual Studio 2008 C++ application where a function Foo::CreateBar uses an internal function to populate a buffer with some data as below. I understand that VS2008 will use return value optimization (RVO) to ensure the Foo::GetData() call will not incur a copy, but will I incur copies for the Bar constructor? How about for returning the Bar object from Foo::CreateBar Is there a more efficient way to do this? Do I need to redefine my Buffer as boost::shared_ptr< std::vector< BYTE > >?
typedef std::vector< BYTE > Buffer;
class Bar
{
public:
    explicit Bar( Buffer buffer ) : buffer_( buffer ) { };
    // ...
private:
    Buffer buffer_;
};
class Foo
{
public:
    Bar CreateBar() const { return Bar( GetData() ); };
    // ...
private:
    static Buffer GetData()
    {
        Buffer buffer;
        // populate the buffer...
        return buffer;
    };
};
Thanks, PaulH


