Boost logo

Boost :

Subject: Re: [boost] [bitstream] Copy stream buffer or pass pointer?
From: Dave Abrahams (dave_at_[hidden])
Date: 2013-07-18 03:27:37


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;
>>
>> I don't think either way is more correct than the other. The reason I
>> don't copy is for memory and CPU performance, thinking that the streams
>> a bit-stream library typically processes are larger than the streams
>> that a string-stream library processes and are more time critical. I
>> very well may be mistaken, though. Anyway, what do you people think?
>> Copy or don't copy? Maybe I should do copies just to follow the
>> semantics of std::stringstream.
>
> I would suggest copying.

But when the source is an rvalue, move instead. That handles the
efficiency issues.

-- 
Dave Abrahams

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk