> Joseph Artsimovich wrote:
> > char*
> > Query::preview_char()
> > {
> > std::string const str(sbuffer_.str());
> > char* s = new char[str.size() + 1];
> > memcpy(s, str.c_str(), str.size() + 1);
> > }
>
> This makes one more copy than is necessary. Please try the code
> currently in svn, as it should accomplish the same end without the
> double copy.
Actually, my code should be faster than yours.
An extra call to std::stringbuf::str() in your code will likely be slower than
constructing a temporary std::string from another string. On most platforms
the former will allocate memory while the latter will use reference counting.