Boost logo

Boost :

Subject: Re: [boost] [bitstream] Copy stream buffer or pass pointer?
From: Daryle Walker (darylew_at_[hidden])
Date: 2013-07-17 23:21:10


> 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. Here you have two sources; what happens with three? The reference method doesn't scale. By-reference also has lifetime issues.
 
Daryle W.

 
                                               


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