|
Boost : |
Subject: Re: [boost] [bitstream] Copy stream buffer or pass pointer?
From: Paul Long (plong_at_[hidden])
Date: 2013-07-18 18:30:03
On Thu, 18 Jul 2013 00:27:37 -0700, Dave Abrahams wrote:
> on Wed Jul 17 2013, Daryle Walker <darylew-AT-hotmail.com> wrote:
>
>>> Date: Wed, 17 Jul 2013 22:09:08 -0500
>>> From: plong_at_[hidden]
>>>
>>> For example, the following snippet prints
>>> "hello, goodbye".
>>>
>>> char c[BUFSIZ] = "hello";
>>> istringstream iss(c);
>>> strcpy(c, "goodbye");
>>> cout << iss.str() << ", " << c;
>>>
>>> However, the library I'm working on doesn't copy. Instead, pointers
>>> are
>>> passed in and out. So, for example, this code prints "goodbye,
>>> goodbye".
>>>
>>> char c[BUFSIZ] = "hello";
>>> ibitstream ibs(c);
>>> strcpy(c, "goodbye");
>>> cout << ibs.data() << ", " << c;
>>>
>>> Copy or don't copy?
>>
>> I would suggest copying.
>
> But when the source is an rvalue, move instead. That handles the
> efficiency issues.
I don't understand? Can you elaborate? Wouldn't a move also require
that bytes get copied? Also how does one write code that is overloaded
for rvalues vs lvalues?
Paul
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk