Boost logo

Boost :

Subject: [boost] [bitstream] Copy stream buffer or pass pointer?
From: Paul Long (plong_at_[hidden])
Date: 2013-07-17 23:09:08

While working on a bitstream library I proposed a while back
(, I came
across a design decision for which I'd like to get some feedback.

The proposed bitstream library (
mimics the std::stringstream class hierarchy and semantics as close as
possible. In general, when the consumer of the
std::stringstream/stringbuf classes provides a string for the stream
buffer, a copy gets made; likewise, when it retrieves the stream buffer,
it gets a copy of the string. 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 << << ", " << 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.

Oh, also, am I being presumptuous by including "[bitstream]" in the
Subject header of this post since it's just a _proposed_ library? IOW,
should I stop doing that?


Boost list run by bdawes at, gregod at, cpdaniel at, john at